Magento – Address validation with partial address information (ZIP only)

customercustomer-addressmagento-1.9

I need to add the ZIP field on the sign-up page.

I enabled the setShowAddressFields parameter in order to show address fields, then I overrode the file /template/persistent/register.phtml to show only the ZIP field.

Of course, the address validation fails and so I googled for the solution, but I only found some indication to modify the DB and the Zend validation function. I don't want do that, because I need address fields required during the checkout process.

So, any idea to simply show and store the ZIP field?

Best Answer

Please create local.xml in your theme layout folder.

Refer the code below in local.xml:

<layout version="0.1.0">

    <customer_account_create> 
      <reference name="customer_form_register">   
        <action method="setShowAddressFields">
          <param>true</param></action>    
      </reference>
    </customer_account_create>

</layout>

or

In customer.xml (current theme layout), add the below code in customer_account_create node:

<action method="setShowAddressFields"><value>true</value></action>

so it look like

<reference name="content">          
    <block type="customer/form_register" name="customer_form_register" template="customer/form/register.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>

Clear the cache after added code.

Please find the _basicCheck function in Mage_Customer_Model_Address_Abstract, this validating the registration required fields, so you have to rewrite this function _basicCheck.

Please refer this link its for telephone field (customize for zipcode field), have a look on this. Hope this will helps

Related Topic