How to Add Confirmation email field in magento registration form using class validate-cemail in your customer registration or newsletter page?

 Create a javascript file called validation.js under "js/email/validation.js"
view plainprint?

    Validation.addAllThese([ 
     
        ['validate-cemail', 'Please make sure your emails match.', function(v) { 
                    var conf = $('confirmation') ? $('confirmation') : $$('.validate-cemail')[0]; 
                    var pass = false; 
      var confirm; 
                    if ($('billing:email')) { 
                        pass = $('billing:email'); 
                    } 
      confirm =conf.value; 
      if(!confirm && $('email2')) 
      { 
      confirm = $('email2').value; 
      } 
                    return (pass.value == confirm); 
                }], 
    ]);  

Add the new js file into your customer.xml file
view plainprint?

    <reference name="head"> 
        <action method="addJs"><script>email/validation.js</script></action> 
    </reference>  

On the register form add a new field to contain the email confirmation field "template/customer/form/register.phtml".
view plainprint?

    <label class="required" for="email_address"><em>*</em>CONFIRM EMAIL</label> 
    <div class="input-box"> <input class="input-text required-entry validate-cemail" title="Email Address" value="" id="email2" name="email2" type="text"> 
    </div> 

Thats all. You are done.


for checkout

['validate-cemail', 'Please make sure your emails match.', function(v) {
var conf = $$('.validate-cemail')[0];
var pass = false;
if ($('email')) {
pass = $('email');
}
var emailElements = $$('.validate-email');
for (var i = 0; i < emailElements.size(); i++) {
var emailElement = emailElements[i];
if (emailElement.up('form').id == conf.up('form').id) {
pass = emailElement;
}
}
if ($$('.validate-admin-email').size()) {
pass = $$('.validate-admin-email')[0];
}
return (pass.value == conf.value);
}],
 
return !(pass.length < 7);
    }], 

<div class="field">
<label for="billing:confirm_email" class="required"><em>*</em><?php echo $this->__('Confirm Email Address') ?></label>
<div class="input-box">
<input type="text" name="billing[confirm_email]" title="<?php echo $this->__('Confirm Email') ?>" id="billing:confirm_email" class="input-text required-entry validate-cemail" />
</div>

Comments