Accessing the address fields in php snippet?

By: Roger Weiss | Asked: 04/18/2022
ForumsCategory: Code SnippetsAccessing the address fields in php snippet?
Roger WeissRoger Weiss asked 3 years ago

For credit card processing, I added the address text block. And I want to access address, city, state and zip separately in my php snippet.

I know how to access it in the email settings e.g. [x show="city"]. But how would I access the fields in my php snippet?

I tried:

$city = $_POST['item_meta'][734 show="city"];

But that doesn't work.

Does anyone know how to do this?

Thanks,

Roger

Victor Font replied 3 years ago

PHP $_POST isn't a shortcode. PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables to the server.

You didn't say which hook you're using to access $_POST. But in order to understand how to access post variables, you need to know how Formidable defines the input names. The best way to see this is to use your browser's inspection tool and examine the input names.

For example, I just added an address block to a play form on my development server. When I look at them in the inspector, their field names are item_meta[1109][line1], item_meta[1109][line2], item_meta[1109][city], item_meta[1109][state], item_meta[1109][zip], and item_meta[1109][country].

The 1109 is my field id. Change it to your address block's field ID and you should be set.

Victor Font replied 3 years ago

$_POST generally has a lot of details besides just input values. If you use a debugger like Kint, you can see everything contained in $_POST.

2 Answers
Roger WeissRoger Weiss answered 3 years ago

Thank you very much. This makes total sense, and I will follow up after I get to try it out.

Roger

Roger WeissRoger Weiss answered 3 years ago

I tried this solution and it works great. Thanks a bunch,

BTW, for folsk who need to use this, the last parm needs to be in apostrophes e.g. item_meta[1109]['country']

Roger

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