Forums

Server Validation to check already existing email in table

jupp 08 Jan, 2012
Hello,

first of all congrats to this really great Component.

I´m coming from version 3.1 RC5.5 in J 1.5 where the Server Side Validation (see code below) has worked well.

Now in J 1.7 and ChronoForms 4.0 RC3.0 the Server Side Validation didn´t work.

I wan´t to check if the field name or email already exist in Table #__chronoforms_data_Prinzentipp.

But when I put the following code in Custom Server Side Validation in my form on submit it will always store the data in Table, when the name or email is equal to one in the table, too.

<?php
$db =& JFactory::getDBO();
$name = JRequest::getString('name', '', 'post');
$email = JRequest::getString('email', '', 'post');

$query = "
    SELECT COUNT(*)
        FROM `#__chronoforms_data_Prinzentipp`
        WHERE (`name` = '$name' OR `email` = '$email');
    ";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
    return "name or email does already exist ! Please try another !";
}
?>


Have anyone a suggestion for this problem.

Thanks a lot,

Jupp
GreyHead 09 Jan, 2012
Hi jupp,

You can see from the action Help that the syntax has changes in CFv4.

[list]

  • You should use PHP code with php tags.

  • Returning "boolean" false will fail, anything else or no return at all will lead to success.

  • Set fields errors by adding a new key => value entry to the $form->validation_errors array, where "key" is the "field name" and "value" is the "Error message", for example, if you want to set an error to the "email" field you should use this code
    $form->validation_errors['email'] = "Email error message is here.";
    .
  • [/list]



    You also need to drag an Event Loop action into the On Fail event of this action to re-load the form and display the errors.

    Bob
    jupp 10 Jan, 2012
    Hello GreyHead,

    thank you for your reply. Now it worked for me.

    I´m not really good in coding, so I didn´t understand the Help in Custom Server Side Validation.

    Only with your reply I have figured out where I have to search for the error in my code.

    So thanks for this.

    Best regards,

    Jupp
    This topic is locked and no more replies can be posted.