Hello,
Thanks for the feedback!
Yes you’re right, when a form is rendered inside a Dynamic Preview in the admin, it will typically render a <form>
and <input />
on the page. Which means that WordPress will try to process them when saving the page, which could lead to issues.
If you’re using a custom solution, like WP Forms, to render a form in your Dynamic Template, you’ll have to disable the <form>
tag & the name=""
attributes in the <input />
render. If you don’t have the technical possibility to do it, you can then simply disable the form render when $is_preview
return true
.
The $is_preview
variable is available in all Dynamic Templates to let you know if the template is currently displayed in the admin or the front-end. In your case, you could use the following code in the template.php
file to disable the form render when in preview mode:
<div class="layout-form <?php echo ($is_preview) ? 'is-preview' : ''; ?>">
<h1>Form</h1>
<?php if(!$is_preview): ?>
<?php // Display the form using a function ... ?>
<?php else: ?>
<div class="form-placeholder">Form Placeholder</div>
<?php endif; ?>
</div>
If you’re using some sort of shortcode in a WYSIWYG field, you can disable the shortcode using remove_shortcode()
(See documentation) and replace it with a placeholder, within the acfe/flexible/render/before_template
hook (See documentation). That hook is called before any Dynamic Template include, and you also have access to the $is_preview
variable there.
Note that if you use the ACF Extended Form module, the forms <input />
are automatically disabled. Unfortunately I can’t really implement a universal solution for all others forms solutions, since there are so many plugins and it depends on their usage.
Hope it helps!
Have a nice day.
Regards.