Front End Form Fix for forms on page templates
-
I had an issue where I was using the acf_form() function on a page template and not on the the page or post itself. This caused the incorrect post_id to be submitted and used in some of the validations.
Below is the updated function in validated_field_v5.php
function set_post_id_to_acf_form(){ global $post; ?> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('form.acf-form').append('<input type="hidden" name="acf[post_ID]" value="' + acf.o.post_id + '"/>'); jQuery('form.acf-form').append('<input type="hidden" name="acf[frontend]" value="true"/>'); }); </script> <?php }
The update is to use
acf.o.post_id
in Javascript instead of theglobal $post;
object in php as we may not be on the relevant post or page.I hope this helps someone ??
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Front End Form Fix for forms on page templates’ is closed to new replies.