Make the address field more flexible or structured

By: Bart Baars | Asked: 12/23/2024
ForumsCategory: General questionsMake the address field more flexible or structured
Bart Baars asked 1 month ago
Hi, Reasonable new user here :) Anyway, I would like more flexibility in the address field. Or am I missing something? I want to be able to store all parts of the address field in separate fields instead of one field as it does now. Now FF stores the address like this in the Wordpress accountspage: {"line1":"street 15","zip":"1234TS","city":"Somewhere","country":"some_country"} This is rather unstructured. Because of this, I am unable to allow users to edit their address using a Formidable Form. When doing so, even FF is displaying this string in one field (all in the street name). With the ACF-plugin it's possible to add these fields into the users-profile. But I don't think there currently is any way to do so in FF. Or is it just me?
Mark HansenMark Hansen replied 1 month ago

I use separate fields specifically because its my preference in how I use the data, and use either number or text fields for this information. In the advanced tab, you can set these to automatically populate with the user information stored in their browser profile, and write short codex to assure you get the right data in your forms.

Example, I use a standard text field for postal code. I set the autofill option to "postal code", and have a rule that limits it to 5 characters. ^[0-9]{5}(?:-[0-9]{4})?$

There is no need at all to use the full address field unless you want to.

1 Answers
Rob LeVineRob LeVine answered 1 month ago
You can break apart the stored address value and save it to different fields when the user submits the entry, but my question is why? When you say "I am unable to allow users to edit their address using a Formidable Form" that's not true and I do it all the time. Can you explain how you set up the form using the Address field type such that it's not working?
Bart Baars replied 4 weeks ago

I don't think I did anything special with the address field:
- European scheme
- Removed the 2nd address line
- Translated labels etc.

If I now set a dynamic default value ([user_meta key="adres"]) (adres = translated from address, so no typo) it displays to whole address, incl zip, country, etc, in the street name field.

FF is strictly speaking doing what it's supposed to be doing, as I only set a default value for the street name. So, am I missing something, and am I using the wrong user_meta key?

Rob LeVineRob LeVine replied 4 weeks ago

That's quite likely because the address meta value in wp_usermeta is not in the format that Formidable uses. It uses a serialized string. The best way to see it is to save a value for an address field on a form and then look at the value in wp_frm_item_metas. You'll see something like this:
a:5:{s:5:"line1";s:16:"42 Alibaster Rd.";s:4:"city";s:13:"South Hildale";s:5:"state";s:11:"Mississippi";s:3:"zip";s:10:"50000-9999";s:7:"country";s:13:"United States";}
So, when you're saving the value to wp_usermeta you need to serialize the data. If the information is being saved by another plugin, you'll need to intercept it and reformat it.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right