Forums

Custom Server Side Validation

efh68 17 Jul, 2011
I am trying to add in the following custom validation into my form:

<?php
$error_count = 0;
$phone = $form->data['phone'];
$email = $form->data['email'];
if ( !$phone && !$email ) {
  $form->validation_errors['phone'] = 'Please enter an email or phone number';
  $error_count++;
} 
if ( $error_count ) {
  return false;
}
?>


When I place the code in the onload event it works, but when I place it onto the on submit it is not working. What am I missing?

I am using the default form validation on most to the fields, but I have this special case where you are asked to either enter an email address or phone number. Would using the default form validation be interfering with the custom validation?

Thanks,

Ed
GreyHead 17 Jul, 2011
Hi Ed,

The code looks OK. Have you added an Event Loop action to the OnFail event of this action?

Bob
efh68 18 Jul, 2011
Yes that was it. Thank you so much!
This topic is locked and no more replies can be posted.