3
Answers
Vote up!
1
Vote down!

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

Asked by: Rosamunda
on February 5, 2013

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.
- daemonicus on February 13, 2013

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;
}
}
- daemonicus on February 21, 2013

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;
}
}
- daemonicus on February 21, 2013

3 Answers

Vote up!
1
Vote down!

THANK YOU!!!! :)
That did the trick!

Answer by: Rosamunda
Posted: Mar 14, 2013
Vote up!
0
Vote down!

it didn't work with me ??

with regards

Answer by: aabdullahh
Posted: Mar 16, 2013
Vote up!
0
Vote down!

waaaaaw

it works thank a lot

with regards .....

Answer by: aabdullahh
Posted: Mar 19, 2013