Add custom field in customer registration form in Magento 1.7.X or greater

Before make any changes in code make sure you backup all existing magento app. Below steps shows how to add any custom field in account registration form in magento, all the path shown is for default app and replace <yourstore> should be your current theme:

E.g.: Let you want to add mobile field in form

  1. Add the following code in the form tag in register.phtml and edit.phtml
    app/design/frontend/default/<yourstore>/template/customer/form/register.html

    <div class="input-box">
    <label for="occupation"><?php echo $this->__('Mobile') ?></label><br/>
    <input type="text" name="mobile" id="mobile" value="<?php echo $this->htmlEscape($this->getFormData()->getMobile()) ?>" title="<?php echo $this->__('Mobile') ?>" class="input-text" />
    </div>
  2. Replace the following block of code in
    app/code/core/Mage/Customer/Model/Resource/Setup.php

    'email' => array(
               'type' => 'static',
               'label' => 'Email',
               'input' => 'text',
               'sort_order' => 80,
               'validate_rules' => 'a:1{s:16:"input_validation";s:5:"email";}',
               'position' => 80,
               'admin_checkout' => 1
     ),

    with this

    'email' => array(
               'type' => 'static',
               'label' => 'Email',
               'input' => 'text',
               'sort_order' => 80,
               'validate_rules' => 'a:1{s:16:"input_validation";s:5:"email";}',
               'position' => 80,
               'admin_checkout' => 1
     ),
    'Mobile' => array(
              'type' => 'varchar',
              'label' => 'Mobile',
              'input' => 'text',
              'sort_order' => 80,
              'validate_rules' => 'a:2: {s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
              'position' => 80,
     ),
    
  3. Find the following line of code around line 883  in
    app/code/core/Mage/Customer/controllers/AccountController.php

    $customerData = $customerForm->extractData($this->getRequest());
    

    Add below code after above line:

    //Add to save mobile in database START here
    if($this->getRequest()->getParam('mobile'))
    {
         $customer->setMobile($this->getRequest()->getParam('mobile'));
    } 
    //Add to save mobile in database END here
  4. Add the following code in app/code/core/Mage/Customer/etc/config.xml
    under the customer_account tag

    <mobile>
      <create>1</create>
      <update>1</update>
      <name>1</name>
    </mobile>
    
  5. Put below script on register.phtml (path shown on step 1) header file and  run it only ONCE.
    <?php
    $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
    $AttrCode = 'mobile';
    $settings = array (
      'position' => 1,
      'is_required'=> 1
    );
    $setup->addAttribute('1', $AttrCode, $settings);
    ?>
    

Enjoy !!!

Previous Post

URL Rewrite in web.config for .NET framework 3.5 or greater

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top