I'm building a simple order module for a client and want to incorporate the addresses functionality for users to select a address.
Right now I'm able to populate a select list with the address names and I'm able to put these into the db tabel of my own module.

But I would like a user to have two choices:

  • Select an allready existing address
  • Or create a new address, which needs to be added to the addresses db table and is avaiable in the select list in a future order

This kinda functionality is used in the uc_addresses module.

What would be the best way to do this?
Create new fields and add these to the addresses table?

Hope somebody can help me!

Comments

AlexisWilke’s picture

Hi ptitb,

Since you are writing your own module, I would think you can just directly access the addresses module tables as you see fit. I don't otherwise have any recommendation. You can have a look how Drupal offers drop down functionality. There is a good example in the user module and also the addresses module (for the states.)

Thank you.
Alexis Wilke

sean3z’s picture

@ptitb Just a heads up: if you intend to include the AJAX functionality of the province/country features within a custom form, you will need to include '#validated' => true on any form element you pre-populate '#options' for. Otherwise Drupal will error with 'An illegal choice has been detected. Please contact a site administrator' when a user submits the form.