We setup 2 website/store. When we tried to create customer from a store (i.e. not main store). By using customer/form_register
type form submission. customer created successfully but taxvat
field not saving with customer information. All other required customer attributes firstname
, lastname
, email
saving correctly but only taxvat
attribute not saving.
Code for Load layout with customer/form_register
block type :
<reference name = "content">
<block type = "customer/form_register" name = "customer_form_register" template = "seller/seller.phtml">
<action method = "setShowAddressFields"><value>true</value></action>
<block type = "page/html_wrapper" name = "customer.form.register.fields.before" as = "form_fields_before" translate = "label">
<label>Form Fields Before</label>
</block>
</block>
</reference>
Template File :
<form name="test-form1" id="my-custom-form1" action="<?php echo $this->getPostActionUrl(); ?>" method="post">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl(); ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl(); ?>" />
<div>
<div>
<label>Email <span class="required">*</span></label>
<input type="text" name="email"/>
</div>
</div>
<div>
<div>
<label>First Name <span class="required">*</span></label>
<input type="text" name="firstname"/>
</div>
</div>
<div>
<div>
<label>Middle Name <span class="required">*</span></label>
<input type="text" name="middlename"/>
</div>
</div>
<div>
<div>
<label>Last Name <span class="required">*</span></label>
<input type="text" name="lastname"/>
</div>
</div>
<div>
<div>
<label>Tax/Vat Number <span class="required">*</span></label>
<input type="text" name="taxvat"/>
</div>
</div>
<div>
<div>
<input type="submit" name="sub" value="Submit">
</div>
</div>
</form>
This problem also exist for middlename
, prefix
, suffix
attribute.
All these attributes 'taxvat', 'middlename', 'prefix', 'suffix' are exist in default magento setup same like 'firstname', 'lastname', 'email' exist. the only difference is they are not required.
Can anyone please tell me why this is happened and how to resolve this problem?
Best Answer
This happens because those attributes you mentioned have
is_visible
set to0
in thecustomer_eav_attribute
table. They are saved with this value when they are created by the setup.Before saving the customer data, in the controller (
Mage_Customer_AccountController
) the_getCustomerErrors
function is called:Not all the data you submit from the form gets set on the customer model in order to be saved. The data is first extracted in
Mage_Customer_Model_Form
class, which extendsMage_Eav_Model_Form
. The first condition for the attribute data to be set on the customer model is that the specific attribute should be associated to submited form (you can check these in thecustomer_form_attribute
table by filtering byform_code
customer_account_create). This condition should be met for the attributes you mentioned since they are added to this form when they are created by the setup. The second condition for the attribute data to be set on the customer model is to pass the validation in theMage_Eav_Model_Form::extractData
function:The
_isAttributeOmitted
function will check theis_visible
value:You can check the
is_visible
values for those attribute by running this query on your database:If the value for
is_visible
is0
then you can change it to1
.If you are using Magento Enterprise then you can edit the customer attributes in Customers -> Attributes -> Manage Customer Attributes. If you set Show on Frontend to Yes then the customer attribute values should be saved correctly into the database.