Forums

Check if email address already exist

Joomla-Newbies 04 Sep, 2011
Hi all,

I need some help, I have created a customer registration form, the form is working perfectly can send capture data to emails and can save to the database too. However to prevent existing customers from registerring twice I need to check if their email already exist. I am stuck please help.

Thank you fo your help. As a side note,my form does not have a username field, it is purely for registration purpose only, not for customers to login.
GreyHead 05 Sep, 2011
Hi Joomla-Newbies ,

You can either add a few lines in the ServerSide validation to check the table; or you could use Ajax to run the check from the browser. The main code for the Server Side validation approach is like this:
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__some_table`
        WHERE `email` = '{$form->data['email']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
  $form->validation_errors['email'] = "Email is already registered.";
  return false;
}
?>


Bob
Dinosrules 10 Oct, 2011
Hi,

I am trying to check if an email field is already in the database in my chrono form. I am using a custom server side validation on "on submit" event right after the ReCaptcha validation. However it's not working.

I have replaced the "#__some_table" with my table name and I left the rest untouched because my email field it is called "email".

Am I doing something wrong? Maybe I'm missing something.
Any help would be greatly appreciated.

Thank you!
GreyHead 10 Oct, 2011
Hi Dinosrules,

Have you dragged an Event Loop action to the OnFail event of the Server Side Validation action?

Bob
Dinosrules 10 Oct, 2011
Yes I did that and in fact the form is not stopping. It registers all the data into the db and shows the success message. All my email events and db save actions are placed after the server side validation, so it should stop.

Any other ideas?
GreyHead 10 Oct, 2011
Hi Dinosrules,

Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
Dinosrules 10 Oct, 2011
Hi Bob,

Thank you for your time. My form is attached.
Dinosrules 13 Oct, 2011
Hi Bob,

Any updates on this?
Sciadini 14 May, 2013
Hi,
I had the same problem and I almost solved, that is I insert the code in email field in Auto Server Side Validation and I insert the Event Loop in On Fail of Auto Server Side Validation, the error message is displayed, but the data is the same as recorded in the database... how can I not save the data?

Thank's
Sciadini 14 May, 2013
I Resolved thank's

I moved the Joomla User Registration and the Auto Server Side Validation on DB Save. Order it's important and that both are above DB Save.
This topic is locked and no more replies can be posted.