Non-numeric entry errors in 2 lines of a Wordpress add-on

I get continuing Non-numeric entry errors in 2 lines of a Wordpress add-on:

if ( ! isset( $opts_array[self::$form_data[$field[‘slug’]]-1] ) && self::$form_options[‘email_hide_empty’] == ‘true’ ) {

if ( isset($opts_array[self::$form_data[$field[‘slug’]]-1]) ) {

This is from the radio button entries. There is an else between these lines.

Got a quick fix? Much appreciated!

Occurs to me maybe all the surrounding code will make it easier for you to help me:

case 'radio' :
					// the response is the number of a single option
					// Get the options list
					$opts_array = explode("\n",$field['options']);
					if ( '' == $opts_array[0] && 'checkbox' == $field['type'] )
						$opts_array[0] = $field['label'];  // use the field name as the option name
                    if ( ! isset( $opts_array[self::$form_data[$field['slug']]-1] ) && self::$form_options['email_hide_empty'] == 'true' ) {

                    } else {
					        if ( isset($opts_array[self::$form_data[$field['slug']]-1]) ) {
                                self::$email_msg .= self::make_bold( $field['label'] ) . $inline_or_newline;
					         	//self::$email_fields[$field['slug']] = ' * ' . $opts_array[self::$form_data[$field['slug']]-1];
                                self::$email_fields[$field['slug']] = $opts_array[self::$form_data[$field['slug']]-1];
                                        // is this key==value set? use the key
                                        if ( preg_match('/^(.*)(==)(.*)$/', self::$email_fields[$field['slug']], $matches) ) {
                                             self::$email_fields[$field['slug']] = $matches[1];
                                        }
						        self::$email_msg .=  self::$email_fields[$field['slug']] . self::$php_eol . self::$php_eol;
					         }

One more question. I get these errors about every three hours. The form is not being used more than once a month or so. Why are the errors even generated if the form is not being used?

Thanks. Looking forward to some help :slight_smile:

Not getting any response here? Have I posted in the wrong place for help with this issue?

Wordpress help usually requires someone well versed in WP style code and in the case of an add-on, with specific knowledge of what that add-on is and is supposed to do. You are basically posting a bunch of uncommented code without any context. No one here knows what the variables mean or what they contain.

Does the specific add-on have a dedicated help forum somewhere?

Posting the actual error messages would help and providing some history of when this started happening would help.

The error is probably because self::$form_data[$field['slug']] should return a number, because it is being used in a subtraction, e.g. the -1, to arrive at a numerical array index, for the $opts_array.

What does adding the following, right before the first line producing the error, show -

var_dump(self::$form_data[$field['slug']]);

Thanks for the replies.

The addon has been abandoned and I have tried dozens of replacements to no avail. Nothing comes close and this is really perfect for me. Except for it seeming to connect at random 12 or so times a day and fill an error_log. There is a backstory to the abandonment. I like reCaptcha V2, radio buttons, file upload on my contact form. Little I find has all three.

The error is a non-numeric value has beem encountered on lines 307 and again in line 310. Those lines are above. They are from the references .php I have shown in the section radio button.

I’ll try the line you posted. Thanks. And if any idea to find out where this might be running “by itself” would be appreciated.

~Bob

If this code is responsible for producing a form field on a web page, the occurrences are due to the page being requested by something - search engine indexing the site, real visitors, bot scripts, …

If this code is responsible for processing a form submission, perhaps the error, only for certain input values, is preventing the completion of the form processing code, so, you are only seeing the errors, not an apparent completion of the form.

Thanks. I always get real and sometimes spam submissions. I can see the site analytics ao know my visitors. I thought the constant errors coul dbe from bots. I do not know enough to be sure.

Might it help ifI posted a bit more code that “appears” to be pertinent to this erro and might change your recommendation of that line of code to insert? What is best to hit to paste code if so? I thought there might be a control I am not finding.

You can post code using bbcode [code][/code] tags, on separate lines by themselves, before and after the code.

The reason for the var_dump() is to see what the value actually is, because php has changed handling of strings containing a number over time, which is likely the cause of the error. If the var_dump() shows a string containing a numeric value, the problem can be corrected by applying intval() to the sting before the subtraction is performed.

OK. If you stil think I should insert that after seeing this, I shall give it a try. And appreciate the help!


// Set up values for unchecked checkboxes and unselected radio types
			else if ( 'checkbox' == $field['type'] || 'radio' == $field['type'] )
				self::$form_data[$field['slug']] = '';
			else if ( 'checkbox-multiple' == $field['type'] )
				self::$form_data[$field['slug']] = array();

			// XXX changed for option to hide labels that do not have field values, like when not required.
			// self::$email_msg .= self::make_bold( $field['label'] ) . $inline_or_newline;

			// Required validate
			// ..different for checkbox-multiple, select types.  Not for hidden, checkbox
			if ( in_array($field['type'], self::$select_type_fields) ) {
				//if ( 'checkbox' != $field['type'] ) {
					// select, select-multiple, checkbox-multiple require at least one item to be selected
                    if ( 'subject' == $field['slug'] && 'select' == $field['type']) {
					   self::$selected_subject = self::validate_subject_select( $field );
					} else if ( 'select' == $field['type']) {
					   self::validate_select( $field['slug'], $field );
                    } else if ( 'true' == $field['req'] ) {
						if ( ! isset($_POST[$field['slug']]) ) {
						self::$form_errors[$field['slug']] = (self::$form_options['error_select'] != '') ? self::$form_options['error_select'] : __('At least one item in this field is required.', 'si-contact-form');
						}
					}
				//}
			} else if ( 'hidden' != $field['type'] && 'attachment' != $field['type'] ) {
                if ( 'true' == $field['placeholder'] && $field['default'] != '' && isset($_POST[$field['slug']])  ) {
                  // strip out the placeholder they posted with
                  $examine_placeholder_input = '';
                  $examine_placeholder_input = stripslashes($_POST[$field['slug']]);
                  if ($field['default'] == $examine_placeholder_input ) {
                       $_POST[$field['slug']] = '';
                  }


case 'radio' :
					// the response is the number of a single option
					// Get the options list
					$opts_array = explode("\n",$field['options']);
					if ( '' == $opts_array[0] && 'checkbox' == $field['type'] )
						$opts_array[0] = $field['label'];  // use the field name as the option name
                                        if ( ! isset( $opts_array[self::$form_data[$field['slug']]-1] ) && self::$form_options['email_hide_empty'] == 'true' ) {

                    } else {
					        if ( isset($opts_array[self::$form_data[$field['slug']]-1]) ) {
                                self::$email_msg .= self::make_bold( $field['label'] ) . $inline_or_newline;
					         	//self::$email_fields[$field['slug']] = ' * ' . $opts_array[self::$form_data[$field['slug']]-1];
                                self::$email_fields[$field['slug']] = $opts_array[self::$form_data[$field['slug']]-1];
                                        // is this key==value set? use the key
                                        if ( preg_match('/^(.*)(==)(.*)$/', self::$email_fields[$field['slug']], $matches) ) {
                                             self::$email_fields[$field['slug']] = $matches[1];
                                        }
						        self::$email_msg .=  self::$email_fields[$field['slug']] . self::$php_eol . self::$php_eol;
					         }
                    }
					break;
Sponsor our Newsletter | Privacy Policy | Terms of Service