2

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
dotancohen
1,1306 silver badges21 bronze badges
asked Oct 29, 2013 at 15:00

3 Answers 3

1

So this is true for Magento 1.9 but I am not sure about the others.

  1. These attributes will be set as required on the table eav_attribute so what you can do here is create a setup script that updates the attributes so that they are not required.
  2. Perform a rewrite of the model Mage_Customer_Model_Address and 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 function validate.
answered Jul 24, 2014 at 14:16
0

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.

answered Oct 30, 2013 at 4:28
1
  • 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.'); } Commented Oct 31, 2013 at 9:09
0

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>
answered Nov 8, 2013 at 11:00
1
  • 1
    this won't work because the address is validated server side also. Commented Nov 8, 2013 at 11:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.