public static function validate_field($posted_field, &$errors, $values, $args = array())
 {
     $defaults = array('id' => $posted_field->id, 'parent_field_id' => '', 'key_pointer' => '', 'exclude' => array());
     $args = wp_parse_args($args, $defaults);
     if (empty($args['parent_field_id'])) {
         $value = isset($values['item_meta'][$args['id']]) ? $values['item_meta'][$args['id']] : '';
     } else {
         // value is from a nested form
         $value = $values;
     }
     // Check for values in "Other" fields
     FrmEntriesHelper::maybe_set_other_validation($posted_field, $value, $args);
     self::maybe_clear_value_for_default_blank_setting($posted_field, $value);
     // Reset arrays with only one value if it's not a field where array keys need to be preserved
     if (is_array($value) && count($value) == 1 && isset($value[0])) {
         $value = reset($value);
     }
     if ($posted_field->required == '1' && !is_array($value) && trim($value) == '') {
         $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg($posted_field, 'blank');
     } else {
         if ($posted_field->type == 'text' && !isset($_POST['item_name'])) {
             $_POST['item_name'] = $value;
         }
     }
     if ($value != '') {
         self::validate_url_field($errors, $posted_field, $value, $args);
         self::validate_email_field($errors, $posted_field, $value, $args);
         self::validate_number_field($errors, $posted_field, $value, $args);
         self::validate_phone_field($errors, $posted_field, $value, $args);
     }
     FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
     self::validate_recaptcha($errors, $posted_field, $args);
     $errors = apply_filters('frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args);
     $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
 }
 public static function validate_field($posted_field, &$errors, $values, $args = array())
 {
     $defaults = array('id' => $posted_field->id, 'parent_field_id' => '', 'key_pointer' => '', 'exclude' => array());
     $args = wp_parse_args($args, $defaults);
     if (empty($args['parent_field_id'])) {
         $value = isset($values['item_meta'][$args['id']]) ? $values['item_meta'][$args['id']] : '';
     } else {
         // value is from a nested form
         $value = $values;
     }
     // Check for values in "Other" fields
     FrmEntriesHelper::maybe_set_other_validation($posted_field, $value, $args);
     if (isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value) {
         $value = '';
     }
     // Check for an array with only one value
     // Don't reset values in "Other" fields because array keys need to be preserved
     if (is_array($value) && count($value) == 1 && $args['other'] !== true) {
         $value = reset($value);
     }
     if ($posted_field->required == '1' && !is_array($value) && trim($value) == '') {
         $frm_settings = FrmAppHelper::get_settings();
         $errors['field' . $args['id']] = !isset($posted_field->field_options['blank']) || $posted_field->field_options['blank'] == '' ? $frm_settings->blank_msg : $posted_field->field_options['blank'];
     } else {
         if ($posted_field->type == 'text' && !isset($_POST['item_name'])) {
             $_POST['item_name'] = $value;
         }
     }
     self::validate_url_field($errors, $posted_field, $value, $args);
     self::validate_email_field($errors, $posted_field, $value, $args);
     FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
     self::validate_recaptcha($errors, $posted_field, $args);
     $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
 }