I need to disable validation for few customer address fields in customer/account/create/ (but only on this page).
Seems like I've messed up with names and can't find out how to fix my code. Folder structure:
Mycompany
|__Mymodule
|__controllers
|__Customer
|__AccountController.php
etc
|__config.xml
Model
|__Customer
|__Address.php
|__Customer.php
config.xml
...
<global>
<rewrite>
<mycompany_mymodule_customer_account_create>
<from><![CDATA[#^/customer/account/create/$#]]></from>
<to>/mymodule/customer_account/create</to>
</mycompany_mymodule_customer_account_create>
<excellence_address_customer_account_createPost>
<from><![CDATA[#^/customer/account/createPost/$#]]></from>
<to>/mymodule/customer_account/createPost</to>
</mycompany_mymodule_customer_account_createPost>
</rewrite>
<models>
<customer>
<rewrite>
<customer>Mycompany_Mymodule_Model_Customer_Customer</customer>
<address>Mycompany_Mymodule_Model_Customer_Address</address>
</rewrite>
</customer>
...
etc
The validate() function will be overridden in Address.php
public function validate()
{
// my validation
}
By filling form under customer/account/create/, even if I've removed 'required' class in form and removed in customer_register_address customer_form_attribute for every attribute_id I don't need @ registration page (e.g. street, city etc.), I still got validation warning message:
Please enter the street.
Please enter the city.
etc
3 Answers 3
So this is true for Magento 1.9 but I am not sure about the others.
- These attributes will be set as required on the table
eav_attributeso what you can do here is create a setup script that updates the attributes so that they are not required. - Perform a rewrite of the model
Mage_Customer_Model_Addressand rewrite the function_basicCheck. Then include or only the validation that your required. For versions 1.8 and lower you will need to rewrite the functionvalidate.
If you see a VarienForm() being run on the page somewhere, it will instantiate the Prototype validation. It is usually in the format var foobar = new VarienForm('foobar-form'); where <form id="foobar-form"...
It should be safe to comment out this function being called if you want to create your own with your own Javascript validation.
-
I still want to validate Phone number there. That's why I said "few fields". Actually I'd like to override Mage/Customer/Model/Adress/Abstract.php function validate() where you got these fields: if (!Zend_Validate::is($this->getCity(), 'NotEmpty')) { $errors[] = $helper->__('Please enter the city.'); }Alex– Alex2013年10月31日 09:09:15 +00:00Commented Oct 31, 2013 at 9:09
For client side only, simply remove class "required-entry" from input element that you don't want any Javascript form validation.
With input validation:
<input id="firstname" class="input-text required-entry" type="text" maxlength="255" title="First Name" value="" name="firstname"></input>
Without:
<input id="firstname" class="input-text" type="text" maxlength="255" title="First Name" value="" name="firstname"></input>
-
1this won't work because the address is validated server side also.Marius– Marius2013年11月08日 11:36:30 +00:00Commented Nov 8, 2013 at 11:36
Explore related questions
See similar questions with these tags.