Title: Custom Validation Filter
Last modified: August 21, 2016

---

# Custom Validation Filter

 *  Resolved [Chris](https://wordpress.org/support/users/web2guru/)
 * (@web2guru)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/custom-validation-filter/)
 * 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://wordpress.org/plugins/si-contact-form/](https://wordpress.org/plugins/si-contact-form/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/custom-validation-filter/#post-5025111)
 * Hi Web2Guru I am not sure if you have read the following [URL](http://www.fastsecurecontactform.com/modify-email-fields-before-export).
   It might help you with your question.
 * Kind regards
 *  Thread Starter [Chris](https://wordpress.org/support/users/web2guru/)
 * (@web2guru)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/custom-validation-filter/#post-5025114)
 * 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](https://wordpress.org/support/users/web2guru/)
 * (@web2guru)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/custom-validation-filter/#post-5025181)
 * 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);
       ```
   
 *  [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/custom-validation-filter/#post-5025182)
 * 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](https://wordpress.org/support/users/web2guru/)
 * (@web2guru)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/custom-validation-filter/#post-5025187)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/si-contact-form_dde2be.svg)
 * [Fast Secure Contact Form](https://wordpress.org/plugins/si-contact-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/si-contact-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/si-contact-form/)
 * [Active Topics](https://wordpress.org/support/plugin/si-contact-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/si-contact-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/si-contact-form/reviews/)

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 5 replies
 * 2 participants
 * Last reply from: [Chris](https://wordpress.org/support/users/web2guru/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/custom-validation-filter/#post-5025187)
 * Status: resolved