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

  • I have managed to do that using a separate template file for checkout page but I am not able to use #ajax functionality of form field
  • In Drupal 6 it was possible using hook_form_uc_cart_checkout_form_alter(), but in Drupal 7 the address fields are rendered in a different way, and I'm not able to alter the address form fields as desired

What are other ways of changing it?

I used hook_form_alter() with an #after_build callback; I was able to change the field from text field to select option, but the #ajax parameter attached to this is not working.

It seems like ajax callbacks are attached with the hooks at an early stage. Is there any way to have the #ajax property working?


If you are using Addressfield module you can easily do that extending the module itself.

Look into the sites/all/modules/addressfield/plugin/format & you will see address.inc, where you can extend the list of region or city.

You can look for the example in sites/all/modules/addressfield/example/plugin/format to better understanding of the the format which module will accept for extending it for your list values.

  • I am using ubercart. There is address.inc at path modules\ubercart\uc_store\classes\ but this looks more like a class definition. Here is the reference to this class drupalcode.org/project/ubercart.git/blob/refs/heads/7.x-3.x:/…. – mjs Aug 13 '13 at 9:47
  • @mjs Can't help then. Sorry...I don't have experience with ubercart but only Drupal Commerce. I saw you mentioning addressfield, so thought may be they also addressfield for taking address from users.. – RajeevK Aug 13 '13 at 10:07
  • Files that comes with a module or Drupal should never be changed; the problem would be updating the module or Drupal. – kiamlaluno Aug 13 '13 at 13:16
  • @kiamlaluno - Yes I understand. But if somebody has to do list the region name, or some values list for some particular country, they can open a issue, do it and submit the patch. Contributors will happily accept that..I have done the same. – RajeevK Aug 13 '13 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.