I have a form that has a address field holding inputs for: name address phone etc.

I've added a button on this form/field: Load my data which I would like to load user details/data. On click it should load a corresponding address field from user's profile by ajax and use it to fill in form fields.

Form can have multiple address fields so it should know which address field needs to filled with user data.

Button isn't shown to anonymous users of course.

1 Answer 1


Take a look at how Commerce Addressbook solves these same requirements: https://www.drupal.org/project/commerce_addressbook.

There is a demo video on the project page: https://commerceguys.com/blog/commerce-module-tuesday-commerce-addressbook.

I think if you dig through the module code of that module, you'll find all the logic and code examples you'll need to pull off a similar solution on your custom form.

If you want to see this in action on a local setup, I recommend installing commerce kickstart with commerce addressbook to see how the addresses are organized.

Good luck, Jason

  • Hi! Almost same idea/problem but a bit different solution. Codebase was rather extensive but that figures since the whole solution is a bit more wider than mine. Therefore I couldn't really understand what was going on. However, I've managed to create ajax button that already removes the address field but doesn't replace it since I don't know how I could create a renderable array of user profile field? Commented Jul 13, 2016 at 16:29

Your Answer

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

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