Problem with form not saving updates
-
How can I debug a form not saviny updates to an existing post?
Here’s the exported form if that helps acfe-export-form-photo-add2-2024-10-17.json
Regards
Pete
-
I believe I fixed this
I jumped the gun, it is not saving the post. I have made changes to the underlying field group so here is the json file if it helps.
Many thanks
PeteHello,
Thanks for the feedback!
In your Form Export, your “Post Action” use the target
{form:photo_id}, which means it’s looking for thephoto_idargument in your form to know which “post to update”.This can be passed either using
acfe_form()function:acfe_form(array(
'name' => 'my-form',
'photo_id' => 45, // pass the 'photo_id' to update the post '45'
));Or using
acfe/load_formfilter. See documentation.It looks like this is the form you tried to setup in your previous Topic here. Please read this topic and my answers again to make sure evberything is in order.
In your case, I would recommend to check how the
photo_idis passed to the form in your PHP code.Hope it helps!
Have a nice day!
Regards.
Hi Again,
Yes this is the same form as previously, i have not changed the form, b ut the underlying Field Group has changed. I’ve set the source to {form:photo_id}, and I’m querying the same post to add the Featured Image and Post Title befor the form.
I’ve tried adding a hook to dump the content of the form but it doesn’t seem to be being called.add_action('acfe/form/submit_post/form=photo-add2', 'photo2-front_end_after_save_post', 10, 4);
function photo2_front_end_after_save_post( $form, $post_id ){
error_log( print_r( $form, true ) );
error_log( print_r( get_fields($post_id), true ) );
write_log('Inside PHO - Check data returned (acf extended form)');
// Get ACF fields
}Not sure what else I can do.
Regards
Pete
Hello,
You most likely have an issue at the location where you set the
photo_id = '...'in youracfe_form()function oracfe/load_formhook.I would recommend to check the PHP code where you set this
photo_id, and log the value there to make sure everything is in order.If the
photo_iddoesn’t return a proper Post ID (number), then your “Post Action” will not be executed, as no post can be updated. And thus, theacfe/form/submit_post/form=photo-add2hook won’t be executed.You can check your Form configuration using Global Form hooks (see documentation).
On form load with
acfe/load_form(see documentation):// log form on load
add_filter('acfe/form/load_form/form=photo-add2', 'my_form_load');
function my_form_load($form){
// log
acf_log('load_form', $form);
// return normally
return $form;
}On form submission with
acfe/form/submit_form(see documentation):// log on submit
add_action('acfe/form/submit_form/form=photo-add2', 'my_form_submit');
function my_form_submit($form){
// log
acf_log('submit_form', $form);
}Both these logs should show you
$form['photo_id'] = 45(any number, is should be a post id). If there is no post id, then check your PHP code where you set it.Hope it helps!
Regards.
The topic ‘Problem with form not saving updates’ is closed to new replies.