1

I have a webform with CiviCRM fields on it (webform 7.x.4.1, civicrm_webform 7.x-4.9).

I have configured 2 addresses fieldset, one for work address and one for home address. I find it non intuitive to let the user choose the location for each address and set the first one as the primary. So i have instead defined one field that let the user choose which one is its primary address (simple select field with Home or Work value).

Now, i need to synchronize this with CiviCRM after the form is submitted. I use hook_webform_submission_insert and hook_webform_submission_update.

My question is : what is the best way to define which address is the primary for a contact (the address are already saved in the database). Api ? other ?

Alternative question : maybe there is another (more simple) way to do the same thing ?

1 Answer 1

5

Webform-CiviCRM will always set the first address as "primary".

You don't need to expose the location-type field if you don't want to - you can set it on the backend form. This has the downside of forcing the location type of the primary address to change to whatever you've set the first address to.

Here is a solution that will solve your problem for both creating and updating contacts, and you don't need to resort to custom code and hooks:

  • Set the location-type field for both addresses to be exposed (user select)
  • Change both location-type webform fields to type "hidden"
  • Set the default value for the first one to be "home" and the other "work"

Now when the user updates their address, the location type will not be changed (your default values will be overwritten by the existing data). But when creating new addresses you'll be setting sensible defaults.

5
  • If i understand correctly, the home address will always be the primary in your case. There is no way for the user to change that. And that's why i need my special field and hook.
    – samuelsov
    Oct 29, 2014 at 13:23
  • The home address will always be primary unless the user is updating their existing record in which case the primary address will be listed first (as always) and the location type will not be changed.
    – Coleman
    Oct 29, 2014 at 15:52
  • also, if webform runs a contribution, and the user enters a different address in the billing block than they do in the regular form address fields, the billing address will become primary Mar 1, 2017 at 0:16
  • @jackrabbithanna Billing address always becoming primary on webform contributions is also discussed here: civicrm.stackexchange.com/questions/18124/…
    – davejenx
    Feb 26, 2018 at 12:39
  • Filed issue against webform_civicrm: Billing address always set to primary when making contribution via webform.
    – davejenx
    Feb 26, 2018 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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