Advertisement:

Validate email field on registration

Aloittaja alleh, kesäkuu 23, 2014, 08:01:46 IP

« edellinen - seuraava »

alleh

Hello,

Recently, some users registering on the forums I manage keep screwing up when they write their email when registering, which means we have to fix that typo or they have to use the resend activation code page. Both of these could easily be countered if the users were asked to write their email twice, I was actually surprised to see this wasn't a feature already.

I've located the code to be in default\Register.template.php and default\scripts\register.js and I got most of it in except it doesn't actually compare the two fields.

I added this verify_email section to register.template.php under the original email field

<dt><strong><label for="smf_autov_reserve1">', $txt['email'], ':</label></strong></dt>
<dd>
<input type="text" name="email" id="smf_autov_reserve1" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['email']) ? $context['email'] : '', '" class="input_text" />
<span id="smf_autov_reserve1_div" style="display: none;">
<img id="smf_autov_reserve1_img" src="', $settings['images_url'], '/icons/field_valid.gif" alt="*" />
</span>
</dd>
<dt><strong><label for="smf_autov_reserve2">', $txt['verify_email'], ':</label></strong></dt>
<dd>
<input type="text" name="email2" id="smf_autov_reserve2" size="30" tabindex="', $context['tabindex']++, '" class="input_text" />
<span id="smf_autov_reserve2_div" style="display: none;">
<img id="smf_autov_reserve2_img" src="', $settings['images_url'], '/icons/field_valid.gif" alt="*" />
</span>
</dd>


and the following two functions copied from the password functions to register.js

  // What is the email state?
function refreshMainEmail(called_from_verify)
{
if (!verificationFields['reserve1'])
return false;

var curEmail = verificationFields['reserve1'][1].value;
var stringIndex = '';

var isValid = stringIndex == '' ? true : false;
if (stringIndex == '')
stringIndex = 'email_valid';

// Set the image.
setVerificationImage(verificationFields['reserve1'][2], isValid, textStrings[stringIndex] ? textStrings[stringIndex] : '');
verificationFields['reserve1'][1].className = verificationFields['reserve1'][5] + ' ' + (isValid ? 'valid_input' : 'invalid_input');

// As this has changed the verification one may have too!
if (verificationFields['reserve2'] && !called_from_verify)
refreshVerifyEmail();

return isValid;
}
 
  // Check that the verification email matches the main one!
function refreshVerifyEmail()
{
// Can't do anything without something to check again!
if (!verificationFields['reserve1'])
return false;

// Check and set valid status!
var isValid = verificationFields['reserve1'][1].value == verificationFields['reserve1'][1].value && refreshMainEmail(true);
var alt = textStrings[isValid == 1 ? 'email_match' : 'email_no_match'] ? textStrings[isValid == 1 ? 'email_match' : 'email_no_match'] : '';
setVerificationImage(verificationFields['reserve2'][2], isValid, alt);
verificationFields['reserve2'][1].className = verificationFields['reserve2'][5] + ' ' + (isValid ? 'valid_input' : 'invalid_input');

return true;
}



The result is this.
SMF doesn't do anything at all, so I'm likely missing something here but I'm not quite sure where to look at anymore so any help is appreciated.

Matthew K.

You need to modify ./Sources/Register.php or ./Sources/Subs-Register.php and make sure that the email addresses in the two fields match, or throw an error into the error array which will return them to the registration form with the errors posted above the form.

alleh

Lainaus käyttäjältä: Labradoodle-360 - kesäkuu 24, 2014, 10:12:08 AP
You need to modify ./Sources/Register.php or ./Sources/Subs-Register.php and make sure that the email addresses in the two fields match, or throw an error into the error array which will return them to the registration form with the errors posted above the form.

Thank you, that was it for Sources/Register.php but I also had to modify Sources/Subs-Members.php.




Matthew K.

Ah, that's where it is. Sorry, been a while since I've modified the registration process.

Advertisement: