1

I want to extend the customer Registration form of the frontend with some custom customer attributes. I tried a TextBox and a RadioButton. The TextBox works perfektly. But the RadioButton value won't stored.

What is wrong?

I added a sql scipt

...
$installer->addAttribute('customer', 'test2', array(
    'type'              => 'int',
    'input'             => 'select',
    'source'            => 'eav/entity_attribute_source_boolean',
    'label'             => 'Test2',
    'global'            => 1,
    'visible'           => 1,
    'required'          => 0,
    'default'           => 0,
    'sort_order'        => 130
));

$attribute = $eavConfig->getAttribute('customer', 'test2');
$attribute->setData('used_in_forms', $forms);
//$attribute->setData('is_user_defined', 0);
$attribute->save();


$installer->addAttribute('customer', 'test', array(
    'type'              => 'text',
    'input'             => 'text',
    'source'            => 'eav/entity_attribute_source_boolean',
    'label'             => 'Test',
    'global'            => 1,
    'visible'           => 1,
    'required'          => 0,
    'default'           => 0,
));

$attribute = $eavConfig->getAttribute('customer', 'test');
$attribute->setData('used_in_forms', $forms);
//$attribute->setData('is_user_defined', 0);
$attribute->save();
...

I extend my config

<global>
    ...
    <fieldsets>
        <customer_account>
            <test>
                <create>1</create>
                <update>1</update>
            </test>
            <test2>
                <create>1</create>
                <update>1</update>
            </test2>
         </customer_account>
    </fieldsets>
    ...
</global>

I extend a copy of register.phtml

        <!--Text Test-->
        <li>
            <label for="test" class="required"><em>*</em><?php echo $this->__('Test') ?></label>
            <div class="input-box">
                <input type="text" autocapitalize="off" autocorrect="off" spellcheck="false" name="test" id="test_1" value="<?php echo $this->escapeHtml($this->getFormData()->getTest()) ?>" title="<?php echo $this->quoteEscape($this->__('Test')) ?>" class="input-text required-entry" />
            </div>
        </li>

        <!--Radio Button Test-->
        <li class="field">
            <label class="required"><em>*</em><?php echo $this->__('Do you want to ...?');?></label>

            <div class="field">

                <!--Yes-->
                <input type="radio" id="yes_test2" name="test2" value="0" <?php if($this->getFormData()->getTest2()): ?> checked="checked"<?php endif; ?> class="validate-one-required-by-name" />
                <label for="yes_test2">
                    <span title="<?php echo $this->__('Yes');?>"><?php echo $this->__('Yes');?></span>
                </label>

                <!--No-->
                <input type="radio" id="no_test2" name="test2" value="1" checked="checked" class="validate-one-required-by-name" />
                <label for="no_test2">
                    <span title="<?php echo $this->__('No');?>"><?php echo $this->__('No');?></span>
                </label>

            </div>
        </li>
  • Have you tried someting? – Amit Bera Nov 10 '15 at 14:44
  • I tried some hints, but it doesn't work. I added the attribute to the customer_account_create form of the used_in_forms data. Also I added the field to the fieldsets of my custom config. Additionally I named the attribute Id and name of my new input field (radio box). But nothing helped.... – ClassMP Nov 11 '15 at 15:56
1

if you search on Google for your question ("Magento custom attribute customer") you would get several results containing one or two modules that can do this for you and some posts from this site on how to do it yourself

Here is a link to above mentioned results: https://www.google.com/webhp#q=magento%20custom%20attributes%20customer

And a link to a module I've used in previous projects which can also be found amidst these google results: http://www.magentocommerce.com/magento-connect/customer-attributes-by-amasty.html

  • Thx for the info. I found some links before and I did create a the attribute in database. I copied the register template and added radio button for testing. But I don't know how the value will be stored in the registration process during the user is registering? – ClassMP Nov 5 '15 at 15:28
  • That's a bit broad to answer here. But basically the data sent from the registration page is handled by a controller and mapped to an object that commits it to the database – Sander Mangel Nov 5 '15 at 15:29
  • Ok so I have to extend the AccountController to update the new field? – ClassMP Nov 5 '15 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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