8

I needed to create two new customer attributes. I have followed the guide from: http://www.fontis.com.au/blog/magento/know-more-about-your-customers-adding-custom-signup-attributes

to create these attributes. I have checked the 'eav_attribute' table in the database and can confirm that both attribute exists. The only thing was that I didn't know how to create a checkbox attribute so I have created both attributes as 'Yes/No'.

from following the code on how to display the field on the registration form I have done:

<li class="control">
<div class="input-box">
    <label for="publisheroffer"><?php echo $this->__('Publisher Offer') ?><span class="required">*</span></label><br />
    <input type="checkbox" name="publisheroffer" id="publisheroffer" value="<?php echo $this->htmlEscape($this->getFormData()->getPublisheroffer()) ?>" title="<?php echo $this->__('Publisher Offer') ?>" class="input-text" />
</div>
</li>

Where the attribute id is 'publisheroffer'. When the account is created it creates fine but the custom attribute fields don't change.

How do I display this attribute as a checkbox on the registration page, and how to process the values.

Thanks for all the help in advance.

  • Magento custom registration field module is really nice way to extend magento user registration , work very well with other module as well like marketplace store.webkul.com/Magento-Extensions/… – webkul May 1 '14 at 16:36
12

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();
}
|improve this answer|||||
  • Hi, the attributes are allowable on the registration forms. I have done the same process for 'text' input types and they update fine on submitting registration. The problem I'm having is that I need to used a 'yes/no' input type which is a check box on the registration form. – user1669256 Jul 22 '13 at 9:12
  • Why not set into the html tag input the attribute checked when the value of $this->getFormData()->getPublisheroffer() == 1. You will have <input ... value="1" <?php echo ($this->getFormData()->getPublisheroffer() == 1): 'checked' : ''; ?>You should remove value="<?php echo $this->htmlEscape(...)" and set value="1" (or else) – Sylvain Rayé Jul 22 '13 at 18:11
0

You can try the following code to create a checkbox custom attribute.

$customerSetup->addAttribute(Customer::ENTITY, 'customer_approved', [
            'type' => 'int',
            'label' => 'Customer Approved',
            'input' => 'boolean',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 1001,
            'position' => 1001,
            'system' => 0,
        ]);

        $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'customer_approved')
        ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
        ]);

        $attribute->save();

Use the input 'boolean' instead of 'checkbox'.

|improve this answer|||||

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