3
Answers
Hiding the postal code field in the address module: hook_form_alter didn´t worked. What am I doing wrong?
I want to programatically hide the postal code field, of the address module.
I´ve unsuccessfully tried this:
function mymodulename_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'commerce_checkout_form_checkout') {
hide($form['commerce_customer_address']['und'][0]['locality_block']['postal_code']);
}
It is not working, what´s wrong with that code? Thanks for your help!
Rosamunda
Comments
Same problem. I want to change address form fields via hook form alter. It's OK when I try e.g. title and add this code:
/**
* Implementation of hook_form_alter()
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
// target a single form
if($form_id == 'commerce_checkout_form_checkout'){
$form['cart_contents']['#title'] = 'My title';
}
}
But when a try to change e.g. postal code size or weight does not work:
/**
* Implementation of hook_form_alter()
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
// target a single form
if($form_id == 'commerce_checkout_form_checkout'){
$form['customer_profile_shipping']['commerce_customer_address']['postal_code']['#size'] = 15;
}
}
Any solution? Thanks.
My solution:
/**
* Implementation of hook_form_alter()
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'commerce_checkout_form_checkout'){
$form['customer_profile_shipping']['commerce_customer_address']['und']['0']['locality_block']['postal_code']['#size'] = 15;
}
}
For Rosamunda:
/**
* Implementation of hook_form_alter()
*/
function mymodule_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'commerce_checkout_form_checkout'){
$form['customer_profile_shipping']['commerce_customer_address']['und']['0']['locality_block']['postal_code']['#access'] = FALSE;
}
}