Signup form: Check for typos in email address?

Discussion in 'Customization & add-ons' started by scott_sm, Mar 6, 2008.

  1. scott_sm

    scott_sm New Member

    Joined:
    Aug 22, 2006
    Messages:
    26
    This seems like it may be resolved with simple coding, but I am PHP-illiterate...

    I would like to do the following:

    - Add a second box for "confirm email address" in the signup form (easy, I can do this)

    - Have the signup.php code check to make sure that both email entries are the same - exactly the same process that it currently does for the double password verification.

    Anyone know how to tweak this code, before I go bug Alex and the support guys? :)
  2. conquermaths

    conquermaths New Member

    Joined:
    Feb 13, 2006
    Messages:
    9
    Quite easy... this is how I did it on my site... edit signup.php and find the following lines (around line 68):

    Code:
        if (!check_email($vars['email'])){
            $error[] = _SIGNUP_PLEASE_ENTER_EMAIL;
        } elseif (($config['unique_email'] && $member_id <= 0) && 
            $db->users_find_by_string($vars['email'], 'email', 1)){
            $error[] = _SIGNUP_INVALID_EMAIL_1.'<br />'.sprintf(_SIGNUP_INVALID_EMAIL_2,'<a href="member.php">','</a>','<br />');
        }
    
    Change to:

    Code:
        if (!check_email($vars['email'])){
            $error[] = _SIGNUP_PLEASE_ENTER_EMAIL;
        } 
        if ($vars['email'] != $vars['email_confirm']){
        	$error[] = 'Email Address and Email Address Confirmation are different.';
        } elseif (($config['unique_email'] && $member_id <= 0) && 
            $db->users_find_by_string($vars['email'], 'email', 1)){
            $error[] = _SIGNUP_INVALID_EMAIL_1.'<br />'.sprintf(_SIGNUP_INVALID_EMAIL_2,'<a href="member.php">','</a>','<br />');
        }
    
    In signup.html add an extra input box like the following:

    Code:
    <input type="email" name="email_confirm" value="{$smarty.request.email_confirm|escape}" size="30" />
    
    Good luck, and hope it helps!
  3. scott_sm

    scott_sm New Member

    Joined:
    Aug 22, 2006
    Messages:
    26
    Great!

    Worked perfectly. Thanks for your help!
  4. siteadmin

    siteadmin aMember Pro Customer

    Joined:
    Dec 19, 2007
    Messages:
    10
    stuck signup page

    Hi,

    Added the code and all was fine, until I tested it with an incorrect confirm address:

    - page stays stuck on error message after correct confirm address is added

    - page remains stuck on error message even when another email address is added to both email inputs

    Any ideas/thoughts on issue and solution?

    Thanks much
  5. magicsquares

    magicsquares New Member

    Joined:
    Mar 23, 2008
    Messages:
    5
    Additional Changes

    Thanks, conquermaths, for your solution.

    I have actually made a few more changes, mainly so that the validation of this additional email address field is treated in the same way as the other fields on the sign-up page.

    Firstly, I added the following definitions to the en-custom.php file:

    Code:
    define('_SIGNUP_INVALID_EMAIL_2', 'Email Address and Email Address Confirmation are different');
    define('_TPL_SIGNUP_EMAIL2', 'Confirm Email Address');
    define('_TPL_SIGNUP_EMAIL2_1', 'Enter your Email Address again');
    
    Then, in the signup.html template itself, after these lines:

    Code:
        jsVal_setRequired(f.email, "#_TPL_SIGNUP_EMAIL#");
        if (f.email)
            f.email.regexp = "JSVAL_RX_EMAIL";
    
    I inserted the following so that the JavaScript initValidation function would validate the email confirmation field before the page is sent back to the server for signup.php to do its own validation:

    Code:
        jsVal_setRequired(f.email_confirm, "#_TPL_SIGNUP_EMAIL2#");
        if (f.email_confirm){
            f.email_confirm.equals = "email";
            f.email_confirm.err = "#_SIGNUP_INVALID_EMAIL_2#";
        }
    
    These additional changes are not strictly necessary, but they do mean that the additional field is handled in the same way that the other fields are.

Share This Page