3

I wish to create new fields in the customer registration form. I just wanted to know whether there is any option to create it from Magento admin panel.

Kindly guide me as am new to magento.

2 Answers 2

2

No, There is no option to create it from admin. You will need to create custom script to create it. You can follow below module steps to create custom attribute.

app/code/local/Custom/Customerattribute/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_Customerattribute>
            <version>0.1.0</version>
        </Custom_Customerattribute>
    </modules>
    <global>
        <resources>
            <customerattribute_setup>
                <setup>
                    <module>Custom_Customerattribute</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </customerattribute_setup>
            <customerattribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </customerattribute_write>
            <customerattribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </customerattribute_read>
        </resources>
    </global>
</config> 

app/code/local/Custom/Customerattribute/sql/customerattribute_setup/mysql4-install-0.1.0.php

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


$installer->addAttribute("customer", "custom_attribute",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Custom Attribute",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "custom_attribute");


$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
        $attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", true)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 1)
        ->setData("is_visible", 1)
        ->setData("sort_order", 100)
        ;
        $attribute->save();



$installer->endSetup();

And finally declare your module

app/etc/modules/Custom_Customerattribute.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Custom_Customerattribute>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Custom_Customerattribute>
  </modules>
</config>

You can change your attribute code and label as per your requirement.

12
  • Thank you so much your reply..! But still the custom attribute is not displayed in the frontend.
    – Ramya
    Commented Nov 30, 2015 at 10:55
  • it will not display automatically in front-end. you will need to call it in template file manually. Commented Nov 30, 2015 at 11:53
  • Yes I called (<?php $_age = $this->getLayout()->createBlock('customer/widget_age') ?> <?php if ($_age->isEnabled()): ?> <li><?php echo $_age->setAge($this->getCustomer()->getAge())->toHtml() ?></li> <?php endif ?>) in form/edit.phtml and form/register.phtml as I wish to include a field for 'age'
    – Ramya
    Commented Dec 1, 2015 at 6:57
  • you can call it like <input type="text" name="age" id="age" value="<?php echo $this->escapeHtml($this->getFormData()->getAge()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Age')) ?>" class="input-text required-entry" /> Commented Dec 1, 2015 at 7:26
  • Thank you. but still I didn't get it. Is there anything else that should be done since am using Magento version 1.9.2.2?
    – Ramya
    Commented Dec 1, 2015 at 7:32
1

I do not have the rep to comment, so I had to answer.

There is no way from admin panel as such. But you can do that custom

I am assuming it for magento 1. And I think the question is already shared in the post:-

http://magento.stackexchange.com/questions/5905/adding-custom-attribute-to-customer-registration-form

You did not explained is it for Magento 2, or Magento 1

In the same post Sylvain Rayé shared the piece of code along with git from where you can download the code to do so.

Answer he shared:-

To allow to publish an attribute in the register form and some others form page, you have to set that the attribute(s) is/are available to those forms.

To do that here is a sample code to put in your sql setup below. You can find the rest of the code I used for my Magento Username module on my github account.

/* @var $installer Diglin_Username_Model_Entity_Setup */

$installer = $this;

/* @var $eavConfig Mage_Eav_Model_Config */

$eavConfig = Mage::getSingleton('eav/config');

$store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$attributes = $installer->getAdditionalAttributes();

foreach ($attributes as $attributeCode => $data) {
    $installer->addAttribute('customer', $attributeCode, $data);

$attribute = $eavConfig->getAttribute('customer', $attributeCode);
$attribute->setWebsite( (($store->getWebsite()) ? $store->getWebsite() : 0));

if (false === ($attribute->getIsSystem() == 1 && $attribute->getIsVisible() == 0)) {
    $usedInForms = array(
        'customer_account_create',
        'customer_account_edit',
        'checkout_register',
    );
    if (!empty($data['adminhtml_only'])) {
        $usedInForms = array('adminhtml_customer');
    } else {
        $usedInForms[] = 'adminhtml_customer';
    }
    if (!empty($data['adminhtml_checkout'])) {
        $usedInForms[] = 'adminhtml_checkout';
    }

    $attribute->setData('used_in_forms', $usedInForms);
}
$attribute->save();

}

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.