To achieve solution for above question, You need to use event observer pattern of magento, their is event called customer_save_before, That will help you to get required answer.
Now, we have to add in our custom module. I am calling my module Customer and it is part of the Npm group. So, the file should be named app/etc/modules/Npm_Customer.xml. Add the following code into this file:
<config>
<modules>
<Npm_Customer>
<active>true</active>
<codePool>local</codePool>
</Npm_Customer>
</modules>
</config>
Next, we need to create the code for the module. The idea behind our code is that we are going to create an observer on the customer_save_before event. Magento has a number of events that we can observe but most are beyond the scope of this article. What is useful is that the customer_save_before event is called both when a customer is created and when a customer makes changes to their account. This means that the one observer will be able to do the work for both events.
All of the code we are writing for our module will be located inside the app/code/local/Npm/Customer/ directory. The first file is etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Npm_Customer>
<version>1.0</version>
</Npm_Customer>
</modules>
<global>
<events>
<customer_save_before>
<observers>
<npm_customer_save_observer>
<type>singleton</type>
<class>Npm_Customer_Model_Customer_Observer</class>
<method>customerSaveBefore</method>
</npm_customer_save_observer>
</observers>
</customer_save_before>
</events>
</global>
</config>
The next step is to create the class that we have just told Magento we are going to use, and should be defined in the file Model/Customer/Observer.php:
<?php
class Npm_Customer_Model_Customer_Observer extends Mage_Core_Model_Abstract
{
/*
* observer for the customer saved event
*/
public function customerSaveBefore($observer)
{
try {
$customer = $observer->getCustomer();
if (null != $customer->getPermissionCode()) {
$customer->setData('group_id', 4); // Set the new customer group
} else {
$customer->setData('group_id', 1); // Set to the default customer group
}
} catch ( Exception $e ) {
Mage::log("customer_save_before observer failed: " . $e->getMessage());
}
}
}
Customers are now automatically assigned to your new group if they supply Permission code from the registration form.
Thanks
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
Best Answer
There is two think: First: Validation is done in front by JS - http://inchoo.net/magento/out-of-the-box-form-validation-in-magento/ You can use one predefined or add yourself.
Second: Validation from backend - Somebody ask how to add field to checkout.
Add new field in checkout
http://excellencemagentoblog.com/blog/2011/10/06/magento-add-custom-fields-checkout-page/
https://indiestechtips.wordpress.com/2011/07/30/how-to-add-custom-field-in-the-billing-and-shipping-address-of-onepage-checkout-in-magento/
Tips: It is just added new field in backend. In frontend it is just array of fields so adding one isn't complicated.