I have to alter cities form field in checkout page under delivery section. I have to change it from a textfield to select options dropdown

I have managed to do that using a separate template file for checkout page but by that i
am not able to use #ajax functionality of form field
In D6 it was possible using hook_form_uc_cart_checkout_form_alter But in D7 the address fields are rendered in a diff way and i'm not able to alter the address form fields as desired
what are other ways of changing it ?

Comments

longwave’s picture

Priority: Critical » Normal
Status: Active » Fixed

Support requests are never critical.

To alter the address fields, you have two options: you can use hook_element_info_alter() to change the #process callback of all address form elements, or you can use hook_form_alter() to add an #after_build callback to the checkout form only, where you should be able to change the city field.

mahimajulka’s picture

Hi,
i used hook_form_uc_cart_checkout_form_alter but here delivery city field cant be accessed for changing
i get access to $form['panes']['delivery']['address'] which has keys
#type
#default_value
#key_prefix
#prefix
#suffix

The problem is that delivery_city form field is not getting accessed from here.
In D6 i used this function for form alteration.

Also, regarding using hook_element_info_alter()
i believe this is to change definition of a type. I want city to change from a text field to a select options form variable.

mahimajulka’s picture

Hi,
Please refer to the comment below.
the issue is still not resolved

hi.chawla’s picture

Priority: Normal » Critical
Status: Fixed » Active

Hi Longwave

Thanks for your reply. Please have a look at the MahimaJulka's reply. We are not able to get hold on to exact fields in the form.

longwave’s picture

Priority: Critical » Normal
Status: Active » Fixed

Please read what I said in #1.

hook_element_info_alter() will let you change the definition of the uc_address type across the entire site. hook_form_alter() with an #after_build callback will let you change it in one specific place.

mahimajulka’s picture

Status: Fixed » Needs work

@longwave
i used hook_form_alter() with an #after_build callback
i was able to change the field from text field to select option .. thanks for this

but the #ajax parameter attached to this is not working.
it seems #ajax callbacks are attached with the hooks at an early stage.
is there any way to have the #ajax tag working ?

ps:
i was able to do this at the template level of checkout page as well.
Over there also i faced the same issue of #ajax not working.
i resorted to using jquery to link select option onchange event to an ajax call.
but im still looking for a better solution.

longwave’s picture

Status: Needs work » Fixed

You could perhaps try #process instead of #after_build, attaching it either to the full form or just the address element; if that doesn't work you will have to replace the entire element #process callback with hook_element_info_alter() instead.

mahimajulka’s picture

@longwave
This is how it worked finally

function mymodule_element_info_alter(&$type){
    array_push($type['uc_address']['#process'], 'mymodule_process_address_field');
}

function mymodule_process_address_field($element, $form_state){
    // here i got the element i wanted to change
   return $element;
}

thanks for all the help

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.