• Resolved manzanogilenrique

    (@manzanogilenrique)


    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!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    CF7 custom validation is poorly designed. Use the Smart Grid’s built-in custom validation mechanism. There is a filter to do this, (see screenshot #21)

    Thread Starter manzanogilenrique

    (@manzanogilenrique)

    i tried adding the filter from the form customization options, but the front still does not show the message, btw, the validation itself seems to work as far as i get the validation errors in the submit response, as it happens with the rest of the fields, but there is not built the span

    add_filter( 'cf7sg_validate_submission','validate_field_submission',10,3);
    
    function validate_field_submission($validation_errors, $submission, $cf7_key){
    
    ? /* $submission an array of <field-name>=>$value pairs one for each submitted field.
    
    ? tabbed/tabled sections fields have arrays as $values.
    
    ? tables within tabs have aray of array as values.
    
    ? if a value is not valid, return a <field-name>=><error message string> pair in the $validation_errors array. The sbumission process will be cancelled and teh user required to correct the field before re-submitting.
    
    ? $cf7_key unique form key to identify your form, $cf7_id is its post_id.
    
    ? */
    
    ? if('planvivemadrid'==$cf7_key ){
    
    ? ? //$validation_errors is an array of field-names=>error messages.
    
    ? ? //these include the simple validation exposed in the CF7 plugin for required fields/special field formats.
    
    ? ? if(isset($validation_errors['select_municipio']) && !is_numeric($submission['select_municipio'])){
    
    ? ? ? $validation_errors['select_municipio'] = '"Debe informar este campo."';
    
    ? ? }
    
    ? }
    
    ? return $validation_errors;
    
    }

    {“contact_form_id”:XXXX,”status”:”validation_failed”,”message”:”Ha habido alg\u00fan error procesando la informaci\u00f3n. Revise los datos introducidos y vuelva a intentarlo.”,”invalid_fields”:[{“field”:”select_municipio”,”message”:”\”Debe informar este campo.\””,”idref”:”municipio”,”error_id”:”wpcf7-f5824-p5832-o1-ve-select_municipio”},{“field”:”codigo-postal”,”message”:”El c\u00f3digo postal debe tener 5 n\u00fameros”,”idref”:”codigo-postal”,”error_id”:”wpcf7-f5824-p5832-o1-ve-codigo-postal”}],”posted_data_hash”:””,”into”:”#wpcf7-f5824-p5832-o1″}

    In this case, the “select_municipio” field does not show the validation message, but “codigo-postal” does, and i don’t get it ??

    Thanks!

    Plugin Author Aurovrata Venet

    (@aurovrata)

    In this case, the “select_municipio” field does not show the validation message,

    Make sure your function returns a value properly (debug the fn itself), these kind of errors are usually linked to some small coding error.

    Hi, I have the same problem. I tried using the “Contact form 7 Modules” [If Invalid] tag but it doesn’t work. I don’t know why, but with a dynamic dropdown field (important, dynamic validate) It doesn’t work too. I tried also adding smart grid-layout filters, but it does not work for me, i tried also the include_blank potion from cf7 select, but i cant, I tried to show an “empty” or invalid option to show It as the preselected one. But i couldn’t validate that option as invalid. And when i was able to do so, i cannot see the error message displayed on my page

    Thread Starter manzanogilenrique

    (@manzanogilenrique)

    I cant find any error, It seems to be all right, but the message is still not displayed in the form

    Plugin Author Aurovrata Venet

    (@aurovrata)

    @gerardfreixa please start your own thread. WP Forum policy.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    @manzanogilenrique I will run some tests on my server and get back to you

    Plugin Author Aurovrata Venet

    (@aurovrata)

    @manzanogilenrique I found an issue on my server, I will release a fix within a day or 2 for this and request you to test it on your server.

    Thread Starter manzanogilenrique

    (@manzanogilenrique)

    OK, Thank You!

    Plugin Author Aurovrata Venet

    (@aurovrata)

    Here is v4.15.4rc1 on the GtiHub repository, kindly manually upgrade to this version and let me know if it fixes your issue.

    Thread Starter manzanogilenrique

    (@manzanogilenrique)

    Hi!

    I tested the new version.

    IT WORKED!

    THANKS A LOT! ??

    Plugin Author Aurovrata Venet

    (@aurovrata)

    ok, thanks for the confirmation. I will release it today.

    Please do leave a review when you have a moment to spare.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Validation error message wont be displayed from dynamic dropdown’ is closed to new replies.