Hello Ian,
Thanks for the detailed report. I ran some tests, and you are right, the Step 2 Form doesn’t retrieves the Query Var. Now I’m thinking about it, it’s perfectly normal because Query Vars are just variables. They aren’t submitted by the form.
In your case, the Query Var exists when displaying the Step 2 Form. But at the submission, the actions are processed in the next page load, and the Query Var isn’t there anymore.
I’ve made a little graph to explain it, hope it’s more clear:
+--------------------------------------------+
| Headers: Empty |
+--------------------------------------------+
| |
| [Display:Form Step1] |
+--------------------------------------------+
Submit
+--------------------------------------------+
| Headers: Step1 Form Data + set_query_var() |
+--------------------------------------------+
| |
| (get_query_var() = data found) |
| |
| [Display:Form Step2] |
+--------------------------------------------+
Submit
+--------------------------------------------+
| Headers: Step2 Form Data |
+--------------------------------------------+
| (get_query_var() = empty) |
| |
| [Display:"Succes!"] |
+--------------------------------------------+
The set_query_var() you’re seeing after the first submission is done by ACF Extended Form, during the Post Create Action. But there is no way to retrieve that data for the next submission, because Query Vars are just a variables (it’s not an input that is sent by the form).
This behavior is perfectly normal, and TBH I’m sorry for giving you inaccurate information in my last answer. I’m kinda tired currently, as I’m working hard on ACF Extended 🙂
But hey! There’s good news. There’s a way to make it work. Please note that you need to update ACF Extended to the latest 0.8.6.5 version, as it introduces the acfe_form_is_submitted() function, which will make your code more clean.
Add this code in your page-form.php file:
// Form: Names
$formStep1Name = 'shopping-setup-competitors';
$formStep2Name = 'shopping-setup-services';
// Form: Step 1
if(!acfe_form_is_submitted()){
acfe_form($formStep1Name);
// Form: Step 2
}elseif(acfe_form_is_submitted($formStep1Name)){
acfe_form($formStep2Name);
// Success!
}else{
echo 'Success!';
}
In your functions.php file, add the following hook:
// This hook let you alter the Form Arguments, and pass custom values too
add_filter('acfe/form/load/form=shopping-setup-services', 'my_acf_form_step2_post_id', 10, 2);
function my_acf_form_step2_post_id($args, $post_id){
// Retrieve Query Var
$step1_post = get_query_var('shopping-setup');
$update_post_id = $step1_post['ID'];
// Set the update post id
$args['update_post_id'] = $update_post_id;
return $args;
}
in your Step 2 Form, change the “Save Target” Template Tag to: {current:form:update_post_id}. You’ll recognize the custom argument we’ve added in the hook here. See screenshot: https://i.imgur.com/Nr1yirw.png
I’ve tested it, and it works nicely. The cool part is that the actual update_post_id value is hidden inside encrypted ACF Form data, and visitors cannot change it manually, as it’s not displayed as plain text in the source code of the page.
Side note: I’ve seen that you enabled the “Load Values” in your Step 2 Form, for the meta field “Services to Shop” (https://www.dropbox.com/s/7pwclmbltmto59t/Screenshot%202020-07-06%2008.05.23.png?dl=0). But unless you already have that data in your newly created post, it won’t display anything. You probably can disable the “Load Values” here.
Have a nice day!
Regards.