Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

data not saving in database from custom field of registration form
 
muk_t
Sr. Member
 
Total Posts:  226
Joined:  2012-07-24
 

Hi,
I am following this this tutorialAdding custom registration field on magento for adding an saving custom field in customer registration form .

But when I see the my account information in Magento the newly added field is blank.

1)app/code/local/mage/customer/etc/config.xml.

I added this code under

<global><fieldsets>
section.

<occupation>
                    <
create>1</create>
                    <
update>1</update>
                    <
name>1</name>
 </
occupation>

2)app/code/core/mage/customer/model/Resource/Setup.php

inside

public function getDefaultEntities()
I added following

'occupation' => array(  
                        
'required'      => true,
                        
'label'         => 'occupation',  
                    ),

3)app/design/frontend/base/default/template/persistent/customer/form/register.phtml

In this file after these

<li class="fields">
                    
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
                
</li>
                <
li>
                    <
label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address'?></label>
                    <
div class="input-box">
                        <
input type="text" name="email" id="email_address" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
                    </
div>
                
</
li>

lines I put my code as

<li>
                    <
label for="occupation" class="required"><em>*</em><?php echo $this->__('Occupation #'?></label>
                    <
div class="input-box">
                        <
input type="text" name="occupation" id="ssn" value="<?php echo $this->htmlEscape($this->getFormData()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text required-entry" />
                    </
div>
 </
li>

4)app/code/local/mage/customer/controllers/accountController.php

I replaced this

$customerData $customerForm->extractData($this->getRequest());
line with following code

$customerData $customerForm->extractData($this->getRequest());
               
//new code added to save occupation in database start here
                
if($this->getRequest()->getParam('occupation'))
                 
{
                     $customer
->setOccupation($this->getRequest()->getParam('occupation'));
                 

                  
//new code added to save occupation in database end here

I also added following code on top of register.phtml file

<?php $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer''occupation', array(
        
'label'         => 'Occupation',
        
'type'          => 'varchar',
        
'input'         => 'text',
        
'visible'       => true,
        
'required'      => true,
        
'position'      => 1,
        ));  
?>

Under “eav_attribute “ I have ocupation visible.

Please suggest some solution for this.
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top