Magento Adding a field to the user registration (GO)

Source: Internet
Author: User

Step I Add a occupation/title field to the user registration page, almost 54 lines in register.html, add a occupation display code below the email

Code:
<li>
<div class= "Input-box";
<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 ')?> "class=" Validate-email Required-entry input-text "/>
</div>
<div class=" Input-box ";
<label for=" occupation " ><?php echo $this->__ (' Occupation/title ')? ></label><br/>
<input type= "text" Name= " Occupation "id=" occupation "value=" <?php Echo $this->htmlescape ($this->getformdata ()->getoccupation ()) ?> "title=" <?php Echo $this->__ (' occupation ')?> "class=" Input-text "/>
</div>
</li



This is, if you go to the User registration page, you will see the new fields.

Step 2 Also in edit.phtml, add occupation display block

Code:
<li>
<div class= "Input-box";
<label for= "email" ><?php ech o $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 ')?> "class=" Required-entry validate-email Input-text "/>
</div>
</li>
<li>
<div class=" Input-box ";
<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 ')?> "class=" Input-text "/>
</div
</li>



Step 3, open model/entity/setup.php almost 93 lines, below the email, add the relevant code of Occupation:

Code:
‘email‘ => array(
‘type‘ => ‘static‘,
‘label‘ => ‘Email‘,
‘class‘ => ‘validate-email‘,
‘sort_order‘ => 60,
),
‘occupation‘ => array(
‘label‘ => ‘Occupation‘,
‘required‘ => false,
‘sort_order‘ => 65,
),



Step 4: Now the code is basically written, but we still need to perform a database operation to add the occupation attribute to the Eav_attribute table, putting the following block of code:

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


Put it in the appropriate file and execute it once. I recommend putting it at the top of the register.html file and then revisit register.html. View the database Eav_attribute table to see the new entries. Then remove the above code from the register.phtml.


Step 5: Finally need to edit App/code/core/mage/customer/etc/config.xml's <fieldsets> tag to declare how the field handles insertions and expensive updates

Code:
<fieldsets>
<customer_account>
.....
<occupation><create>1</create><update>1</update></occupation>
</customer_account>
</fieldsets>

Magento Adding a field to the user registration (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.