Joonas
Joonas

Reputation: 2182

How to show custom field in magento's registration page?

I'm a newbie with magento. I have created a custom module which should add custom fields to the customer registration page. I have successfully added one custom field to customer which i can see on admin/customer when editing customers or adding new. How i can make it show also on the registration page?

Here's my module's install file:

mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'resale', array(
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'Resale number',
    'visible'       => 1,
    'required'      => 1,
    'user_defined' => 1,
));

$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'resale',
 '999'  //sort_order
);

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'resale');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();

$installer->endSetup();

Thank you.

Upvotes: 0

Views: 1587

Answers (1)

vikcherniy
vikcherniy

Reputation: 680

You should add code to register.html like below:

<div class="field">
  <label for="my_attribute" class="required"><em>*</em><?php echo $this->__('My Attribute') ?></label>
  <div class="input-box">
    <input type="text" name="my_attribute" id="my_attribute" value="<?php echo $this->htmlEscape($this->getFormData()->getMyAttribute()) ?>" title="<?php echo $this->__('My Attribute') ?>" class="input-text required-entry" />
  </div>
</div>

Upvotes: 1

Related Questions