server side validation

parkplace 16 Sep, 2014
I tried to use the server side validation with no success with the following code:

<?php
 $email = ($form->data['email']);
        $telefon = ($form->data['telefon']);


        if  (($email =="") && ($telefon =="")) {
            $form->validation_errors['telefon'] = "Bitte geben Sie entweder EMail oder Telefon an!";
        }
       $count = count($form->validation_errors);
       

        if ($count > 0 )  {

            return false;
        }
?>


One of the fields Email or Telefon should be filled, if you want to sent out the form.

If nothing filled has the variable $count=1, then I don't get an validation error and the form send it out. In this case, the form should not sending out. What can be the reason for this. Do I have a thinking error?

Thank you in advanced

Robert
parkplace 16 Sep, 2014
I did read the documentation before, but I didn't find a solution.

Thanks.
GreyHead 16 Sep, 2014
Answer
1 Likes
Hi Robert,

The code you have here is for CFv4 and won't work in CFV5 :-(

There is no Custom Serverside Validation action in CFv5 but you can use an Event Switcher action from the Validation actions group in the same way. Here's some code I just tested that appears to do what you need:
<?php
if ( !$form->data['email'] && !$form->data['telefon'] ) {
  $form->errors[] = 'Bitte geben Sie entweder EMail oder Telefon an!';
  return 'fail';
}
?>

Bob
parkplace 16 Sep, 2014
Thank you very much for your help. It is working. :-)
This topic is locked and no more replies can be posted.