2

I need to disable validation for few customer adress 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
   ect
   |__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

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
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.
| improve this answer | |
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.

| improve this answer | |
  • 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 Oct 31 '13 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>
| improve this answer | |
  • 1
    this won't work because the address is validated server side also. – Marius Nov 8 '13 at 11:36

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.