Custom Account/Registration Fields

Our goal was to add a few fields to the standard Magento Registration form (Magento 1.4x, using the default template structure), enabling us to capture information such as Occupation, and Education.

Magento provides a simple user account signup page. However, some online stores might want to collect relevant customer information for more targeted and personal interactions with their customers. Some examples of details that could be collected include occupation, education etc…

Adding your custom fields on the signup form is not difficult, but it is not trivial either, since one cannot use the Magento backend for the task. As an example of how it can be done, I will demonstrate the addition of a new custom field to the signup form asking new users to enter their occupation and education.
Okay, Let me follow step by step. Please do not miss any single step otherwise it won’t work…
Step 1 :

Open File :

app\design\frontend\base\default\template\customer\form\register.phtml

1. Find below code

<div>
<label for="email_address"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br/>
<input type="text" name="email" id="email_address" value="<?php echo $this-
>htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email
Address') ?>" />
</div>

Replace Code

<div>
<label for="email_address"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br/>

<input type="text" name="email" id="email_address" value="<?php echo $this-
>htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address')
?>" />

</div>

<div>

<label for="occupation"><?php echo $this->__('Occupation') ?></label><br/>

<input type="text" name="occupation" id="occupation" value="<?php echo
$this->htmlEscape($this->getFormData()->getOccupation()) ?>" title="<?php echo $this-
>__('Occupation') ?>" />

</div>

<div>

<label for="education"><?php echo $this->__('Education') ?></label><br/>

<input type="text" name="education" id="education" value="<?php echo $this-
>htmlEscape($this->getFormData()->getEducation()) ?>" title="<?php echo $this->__('Education')
?>" />

</div>

step 2:

Open file :

app\design\frontend\base\default\template\customer\form\edit.phtml

1. Find Below Code

<li>
<div>
<label for="email"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br />
<input type="text" name="email" id="email" value="<?php echo $this-
>htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__('Email
Address') ?>" />
</div>
</li>

Replace Code

<li>
<div>
<label for="email"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br />
<input type="text" name="email" id="email" value="<?php echo $this-
>htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__('Email
Address') ?>" />
</div>
</li>

<li>
<div>
<label for="occupation"><?php echo $this->__('Occupation') ?> </label><br/>
<input type="text" name="occupation" id="occupation" value="<?php echo
$this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this-
>__('Occupation') ?>" />
</div>
</li>

<li>
<div>
<label for="education"><?php echo $this->__('Education') ?> </label><br/>
<input type="text" name="education" id="education" value="<?php echo
$this->htmlEscape($this->getCustomer()->getEducation()) ?>" title="<?php echo $this-
>__('Education') ?>" />
</div>

</li>

Step 3:

Open file :

app\code\core\Mage\Customer\Model\Entity\Setup.php

1. Find below code inside getDefaultEntities() function

Replace Code :

'email' => array(
'type'
=> 'static',
'label'
=> 'Email',
'class'
=> 'validate-email',
'sort_order' => 6,
),
'occupation' => array(
'label'
=> 'Occupation',
'required' => false,
'sort_order' => 7,
),
'education' => array(
'label'
=> 'Education',
'required' => false,
'sort_order' => 8,
),

Note: (if you need field with validation then ‘requirted’ => true)

Hey do not feel tired or boring  you are going right way. You are now only Two steps to get it done.

Step 4 :

Open file :

app\code\core\Mage\Customer\etc\config.xml

1. Find below Code :

<global>
<fieldsets>
<customer_account>

Then In <customer_account>, you will find below line

<email><create>1</create><update>1</update></email>

After that line insert 2 more rows like below :

<occupation><create>1</create><update>1</update></occupation>
<education><create>1</create><update>1</update></education>

Step 5:

(Most important) Please follow below instruction :

1. Open file app\design\frontend\base\default\template\customer\form\register.phtml

2. Add Below code at top of the file,

<?php
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$AttrCode = occupation;
$settings = array (
'position' => 1,
'is_required'=> 0
);
$setup->addAttribute('1', $AttrCode, $settings); ?>

Now Save file Clear Cache from admin panel Refresh create account page

For Example, (http://websitename/ index.php/customer/account/create/)

Once Refreshed, then

Go to the customer_entity_varchar table in DB, your field is there…

Again Open file, app\design\frontend\base\default\template\customer\form\register.phtml

Now Replace Top code,

<?php
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$AttrCode = education;
$settings = array (
'position' => 1,
'is_required'=> 0
);
$setup->addAttribute('1', $AttrCode, $settings); ?>

Or Else put

$AttrCode = education;

Now Save file Clear Cache from admin panel Refresh create account page

For Example, (http://websitename/ index.php/customer/account/create/)

Once Refreshed then,

Again go to file, app\design\frontend\base\default\template\customer\form\register.phtml

And Comment Top Code or remove top code….

$AttrCode = education;

Now create your account and login with your information…

Check my account page and get smile….:)

That’s it…………….

Feel Free to ask if you are having any doubt in this.
credit goes to Magento developer : Vipul Prajapati

17 Responses to “Custom Account/Registration Fields”

  • kaban says:

    Hello :)

    It’s not working for me… I copy&pasted your code, but datas do not save. The fields in edit form are empty.

    In eav_attribute table I see this attributes.

    • vipul says:

      Hello kaban,

      Can you please delete entry from eav_attribute(occassion and education) ?

      First delete it from table and then try to refer step 5 again.

      If you have any doubt about step 5 then tell me i will explain more.

      Thanx,

      Vipul Prajapati

  • kaban says:

    here is my code

    register.phtml
    http://wklej.org/id/481628/
    edit.phtml
    http://wklej.org/id/481629/

    the array in Setup.php
    http://wklej.org/id/481630/

    global scope in config.xml
    http://wklej.org/id/481631/

    I would be greatfull for help :)

  • luiskha says:

    Hi! I’m tring to implement the code for adding Custom Account/Registration Fields but, when i modify the file “register.phtml” nothing happens in my front page. Even if I delete one part of code in this file, nothing happens.

    So i guess that i’m modifying the wrong file, i followed the path “app\design\frontend\[My_theme]\default\template\customer\form\register.phtml” I don’t know if there are other files to be modified .. Am I doing something wrong? any ideas?

  • Leana says:

    Hello,

    Thank you for your tutorial.

    I’m trying to add a new attribute for customers, but I can’t see my attribute from magento admin.
    I clear/refresh the cache.
    I found the attribute in eav_attribute table, but my value wasn’t save in customer_entity_varchar table.

    Any ideas? Please help

  • Mohammad says:

    Not a complete code.Can you explain in more detail.

  • Shiv says:

    Hello, great tutorial!!
    I added registration fields to my form but now i want to add an image into registration fields..Can this be possible?? Please help!!

  • Pablo says:

    Hi, I have a problem, at the frontend work but in the backend doesn’t work. When I go in Customer Information – Account Information my field is not ther. What I miss?

  • Manoj says:

    but for enter the the new attribute value into database

    open app/code/local/Mage/Customer/controllers/AccountController.php

    and write following code in createPostAction() method $customer->setCountry($this->getRequest()->getPost(‘country_id’));

    also can write

    $customer = Mage::getModel(‘customer/customer’)
    ->setFirstname($this->getRequest()->getPost(‘firstname’))
    ->setLastname($this->getRequest()->getPost(‘lastname’))
    ->setEmail($this->getRequest()->getPost(‘email’))
    ->setOccupation($this->getRequest()->getPost(‘occupation’)) //Add this
    ->setPassword($this->getRequest()->getPost(‘password’))
    ->setConfirmation($this->getRequest()->getPost(‘confirmation’))
    ->setId(null);

  • shailesh says:

    Hi! i need a ‘select (dropdown)’ userdefined field in registration page, i have make the entry in eav_attribute table for this field.

    can you tell me how i can access it in register.phtml page

    Thanks

  • Harishwebs says:

    Hi,
    I try it Its not working and now how can we remove these fields
    from registration form??. Its showing required error.

    Thanks

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories