• Resolved jensnilsson

    (@jensnilsson)


    Hello!

    I’m using the preview functionality and its generally working perfectly. Except for when I have a Flexible Content component that shows a form from WP Forms, It’s preventing me to publish/update the page because wp thinks I’m trying to submit the “inner” form as well.

    Any ideas on how to work around this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    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.

    Thread Starter jensnilsson

    (@jensnilsson)

    Hi Konrad!

    Thanks for the quick and elaborate response ??
    The solution works like a charm.

    Thanks for a great plugin ??

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear it now works as expected ??

    Thank you for the kind review!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP Forms form in Flexible Content preview’ is closed to new replies.