Add New Field To Magento Registration

Adding new field to magento new customer registration can be done in 4 simple steps, Steps are given below Follow them and u are done with it

Open register.phtml ( in the path: /app/design/frontend/default/default/template/customer/form/).

We accomplished our goal by following these four

Step 1. We added php and html form elements necessary to create new input boxes for each additional field in register.phtml.
[php]
<div class="input-box">
<label for=”company_name”><?php echo $this->__(‘Company Name’) ?></label><br/>
<input type="text" name="company_name" id="company_name" value="<?php echo $this->htmlEscape($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__(‘Company Name’) ?>" class="input-text" />
</div>
[/php]
Step 2: We need to add elements under “getDefaultEntities()” in Setup.php (path: /app/code/core/Mage/Customer/Model/Entity/), one for each additional field created above:
[php]
‘company_name’ => array(
‘label’ => ‘Company Name’,
‘required’ => false,
‘sort_order’ => 64,
),
[/php]

Step 3: Add to the content of $customer in AccountController.php (path: /app/code/core/Mage/Customer/controllers/)
by grabbing the new fields from posted info, in the createPostAction() function:

[php]
$customer = Mage::getModel(‘customer/customer’)->
setCompany($this->getRequest()->getPost(‘company_name’));
[/php]

4) Finally, we will need to add database records to table eav_attribute, corresponding to the newly created fields. The idea is to add to the associated data model, where newly defined model data is entered as the “attribute_code”, with the corresponding entity_type_id (which for this data happens to be ‘1’).

Using your favorate SQL editor (i.e. phpMySQL or sqlYog — highly recommended), execute the following SQL statement for each field created above (replacing ‘company’ and ‘Company Name’ with the respective field name information as required):

[sql]
INSERT INTO eav_attribute (entity_type_id, attribute_code, backend_type, frontend_input, frontend_label, is_global,is_visible, is_required, is_configurable, is_filterable_in_search) VALUES(’1′, ‘company’, ‘varchar’, ‘text’, ‘Company Name’, ’1′, ’1′, ’0′, ’1′, ’1′);

[/sql]

Leave a Comment

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

*