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.