setQuery($query);$in_use = $db->loadResult();if ( $in_use) { return "That email is already registered";}?>As I said it is a 2-page form, so I have tried the above code in the OnSubmit before email box for each of the forms and the mother form. Where should it go? And does anyone know why it's not working?All the best,Al"> Disallow duplicate database entries - Forums

Forums

Disallow duplicate database entries

alryalls 03 Aug, 2010
Hey guys,

I have a questionnaire 2-page setup and chronoforms emails the user upon completion of the questionnaire and provides a randomly generated code as a discount voucher code.

Naturaly we don't want people using the same email address more than once, so from searching the forum I have been attempting to implement the following code in the OnSubmit before email box:

<?php
$email  = JRequest::getInt('email', '', 'post');
if ( !$email ) {
    return "You must enter an email address";
}
$db =& JFactory::getDBO();
$query = "
    SELECT count(*)
        FROM `registration_mother`
        WHERE `email` = ".$db->Quote($quote)." ;
";
$db->setQuery($query);
$in_use = $db->loadResult();
if ( $in_use) {
    return "That email is already registered";
}
?>


As I said it is a 2-page form, so I have tried the above code in the OnSubmit before email box for each of the forms and the mother form. Where should it go? And does anyone know why it's not working?

All the best,

Al
nml375 03 Aug, 2010
Hi Al,
That code is designed to be used with Serverside Validation, not the "on submit before email". Head over to the validation tab in the forms editor.

/Fredrik
alryalls 03 Aug, 2010
Hi Frederick,

Thank you so much for your advice, I feel like a fool for missing that!!

One other thing, where will I find the CSS to style the cf_alert message that displays if you try to register twice.

Thanks again,

Al
nml375 03 Aug, 2010
Hi Al,
The CSS declaration for span.cf_alert is hardcoded within chronocontact.html.php around line 101.
You could, however, use the Custom CSS input (on the Form Code tab) to add your own styling, such as:
span.cf_alert {
  color: #000;
}


/Fredrik
alryalls 03 Aug, 2010
Thanks Fredrik, that's great.

Thanks for your help,

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