Validation error message wont be displayed from dynamic dropdown
-
Hi!
I made a form with a custom sql-filled dynamic select, then i wrote validation function in functions.php, i am able to validate the field, and i get it in “feedback” call response, but the validation message is not shown in any span.wpcf7-not-valid-tip, as it does happen with the other fields.
I don’t know how to proceed with this issue.
My field in form is: [dynamic_select* contacto id:contacto class:select2 “source:filter”]
In functions.php:
add_filter( 'cf7sg_custom_dynamic_select','select_dynamic_options',10,3); function select_dynamic_options($options, $tag, $cf7_key){ ? ? global $wpdb; ? ?if('contacto'== $tag->name){ ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? $data = ?$wpdb->get_results( $wpdb->prepare( "SELECT id, DESCRIPCION FROM ORIGEN_CONOCIMIENTO "),ARRAY_A); ? ? ? ? ? ? ? ? $options["null"] = array("Seleccione una opción"); ? ? ? ? ? ? ? ? for($i = 0; $i < count($data) ; $i++){ ? ? ? ? ? ? ? ? ? ? $key = $data[$i]['id'].""; ? ? ? ? ? ? ? ? ? ? $val = $data[$i]['DESCRIPCION']; ? ? ? ? ? ? ? ? ? ? $options[$key] = array($val); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? }catch (Exception $e) { ? ? ? ? ? ? ? ? echo 'Caught exception: ', ?$e->getMessage(), "\n"; ? ? ? ? ? ? } ? ? ? ? ? } ? return $options; }
Validation add_filter( 'wpcf7_validate_dynamic_select*', 'dynamic_select_obligatorio_custom_validation_filter', 20, 2 ); function dynamic_select_obligatorio_custom_validation_filter($result, $tag){ ? ? if('contacto'== $tag->name){ ? ? ? ? ? ? //echo "A probar contacto: " . $_POST['contacto'] . "\r\n"; ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? if(!is_numeric($_POST['contacto'])){ ? ? ? ? ? ? ? ? ? ? $result->invalidate($tag,"Debe informar este campo."); ? ? ? ? ? ? ? ? ? ? return $result; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? }catch (Exception $e) { ? ? ? ? ? ? ? ? $result->invalidate($tag,"Error procesando este campo."); ? ? ? ? ? ? } ? ? ? ? } ? ? return $result; }
And the response i get is:
{“contact_form_id”:5824,”status”:”validation_failed”,”message”:”Ha habido alg\u00fan error procesando la informaci\u00f3n. Revise los datos introducidos y vuelva a intentarlo.”,”invalid_fields”:[{“field”:”contacto”,”message”:”Debe informar este campo.”,”idref”:”contacto”,”error_id”:”wpcf7-f5824-p5832-o1-ve-contacto”}],”posted_data_hash”:””,”into”:”#wpcf7-f5824-p5832-o1″}
But the span with .not-valid-tip class is not shown.
Thanks!
- The topic ‘Validation error message wont be displayed from dynamic dropdown’ is closed to new replies.