• Resolved Chris

    (@web2guru)


    I want to add a “re-type phone number” field, similar to the “re-type email” field. I don’t think the plugin can verify one field against another, but there is a validation hook that I think I can use to add my own validation. I don’t see how to access the input values though.

    In the includes/class-fscf-process.php file is this:

    // filter hook for form input validation
    self::$form_errors = apply_filters('si_contact_form_validate', self::$form_errors, self::$form_id_num);

    If the hook sent self::$email_fields or self::$form_data as a variable, I think I could figure it out, but it only sends self::$form_errors and self::$form_id_num. Any help would be much appreciated!

    https://www.ads-software.com/plugins/si-contact-form/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Web2Guru I am not sure if you have read the following URL. It might help you with your question.

    Kind regards

    Thread Starter Chris

    (@web2guru)

    Thanks mbrsolution, but yes I’ve read what’s on that URL – it helped me get as far as I have.

    That won’t work will it? From what I understand, that is for after validation and is just to edit the field before it is sent in an email. I need it to validate that the two phone number fields match and show an error message if they are not the same.

    Thanks,
    Chris

    Thread Starter Chris

    (@web2guru)

    After looking at how some of the other validation is done, I realized the POST variables are accessible, so that worked out perfectly.

    For reference, here is how I did it (my fields were phone and phone2):

    function contact_form_phone2_validation($form_errors, $form_id_num){
      if ( isset( $_POST['phone2'] ) ) {
        $phone  = FSCF_Util::clean_input( $_POST['phone'] );
        $phone2 = FSCF_Util::clean_input( $_POST['phone2'] );
        if ( ( !empty($phone) && empty($phone2) ) || ( !empty($phone) && ($phone != $phone2) ) ) {
          $form_errors['phone2'] =  __( 'The two phone numbers did not match.', 'si-contact-form' );
        }
      }
      return $form_errors;
    }
    add_filter('si_contact_form_validate', 'contact_form_phone2_validation', 1, 2);

    Hi Web2Guru, that is great news. Well done ?? if you don’t mind I might add this function to my troubleshooting post. I will add reference to your name here “Web2Guru”.

    Thank you

    Thread Starter Chris

    (@web2guru)

    Thanks! That would be great! I think it would be most useful under Action Hooks and Filters on the FAQ page.

    It’s not fully compatible though and could easily be extended. That code is specifically for phone and phone2 fields that are not required. I’m probably going to extend it to handle replacing the default required text, and to show different error messages when phone2 is empty versus when it does not match. I’ll also add some comments to the code to help others understand what’s going on and where to make changes.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Validation Filter’ is closed to new replies.