Forums

Verifying e-mail is not in database at submit

jnaylies 22 Jul, 2009
Hi,

New problem with ChronoForm.

I have a subscription form with fields :
name
firstname
e-mail
...
other fields

before validate this form, at the submit but before saving datas in database, i would like to verify that the e-mail address is not in database with another subscription

I presume i have something to put in Form code-->on SubmitEvent Code-->On Submit code - before sending email
but I don't know what and also i don't know how can i stop the subscription in case of e-mail in database

thx
Jérôme
GreyHead 23 Jul, 2009
Hi Jérôme,

Use the serverside validation box on the Validation Tab to check if the email is already in use. The code will be something like:
<?php
$db =& JFactory::getDBO();
$email = JRequest::getString('email', '', 'post);
$query = "
  SELECT COUNT(*) FROM `#__users` WHERE `email` = '$email';
";
$db->setQuery($query);
if ( $db->LoadResult ) {
  return "Cet email est déjà abonné";
}
?>
NB: not tested and will need debugging

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