• Resolved Ian Chapman

    (@ianchapman)


    Overall, I am SO impressed with what this plugin has done.

    However, I have come across an issue that has stumped me. In one of the flexible content fields, when I insert a Gravity Forms shortcode to display a form, it does so, and renders visually as expected.

    The first time I saved the page, everything worked. However, on subsequent edits of the page, it appears the Gravity Form is causing an issue with the page is modified and I click the “Update” button.

    Instead of saving the changes, it shows a copy of the Gravity form. It is almost like the “Update” button is trying to post the contents of the Gravity form rather than the WordPress edit screen.

    I’ve tried turning on “no conflict” mode, as well as disabling HTML5 output in the Gravity Forms settings page, but that didn’t resolve the issue.

    Here are some screenshot links to show you what is happening …

    Rendered preview of Gravity Form: https://www.dropbox.com/s/875aozw4hiwmjel/Screenshot%202020-06-12%2012.28.48.png?dl=0

    Displayed after clicking “Update”: https://www.dropbox.com/s/08y64kx4mc47pmj/Screenshot%202020-06-12%2012.21.44.png?dl=0

    Any help on this issue would be greatly appreciated.

    Thanks,
    Ian

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

    (@hwk-fr)

    Hello,

    Thanks for the feedback. The problem is that you’re already in a global <form> tag in the “Post Edit” screen (which contain <input>: Title, content, ACF fields etc…).

    When you use the Gravity Forms shortcode in your Flexible Content Preview, it prints an another <form> and <input> inside that form, that are not related to the current post or ACF. This mix breaks the native “Post Edit” Update form. This behavior is not limited to Gravity Forms, it’s the same thing for all forms ouput in Layouts Preview Mode (ie: ACF Extended Forms).

    The solution is to not print the Gravity Forms shortcode HTML (or any other forms) in the Preview Mode of the Flexible Content, and instead, print a grey <div> with a text like “Form” for example.

    You can disable a specific shortcode in a layout in the preview mode, using the following method. Here is a usage example within the Layout template.php file:

    
    // Check if we're in Preview Mode (Admin preview)
    if($is_preview){
        
        // Rewrite the shortcode to print a simple text
        add_shortcode('gravity_form', function(){
            
            echo '<div style="padding:50px 0; text-align:center; background:#f4f4f4;">Gravity Form</div>';
            
        });
    
        
    }
    
    // Normal templating part
    $my_sub_field = get_sub_field('my_sub_field');
    // ...
    

    You can also disable the shortcode globally in all previews, in case you have multiple WYSIWYG editors in different layouts, by using this hook:

    
    add_action('acfe/flexible/render/before_template', 'flexible_content_disable_gravity_forms_shortcode', 10, 3);
    function flexible_content_disable_gravity_forms_shortcode($field, $layout, $is_preview){
        
        if($is_preview){
            
            // Rewrite the shortcode to print a simple text
            add_shortcode('gravity_form', function(){
                
                echo '<div style="padding:50px 0; text-align:center; background:#f4f4f4;">Gravity Form</div>';
                
            });
    
            
        }
        
    }
    

    Hope it helps!

    Regards.

    Thread Starter Ian Chapman

    (@ianchapman)

    I figured that was the reason. I just didn’t know if you had a workaround that still allowed rendering of the form. But I understand why that is not the case with the “form inside a form” issue.

    We are using multiple WYSIWYG inputs, so I will have to handle it that way. But I appreciate offering both solutions.

    Thanks,
    Ian

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    There’s maybe a possible solution with Javascript which consist to automatically transform the <form> tag output, and disable any form input. But I still have to dig in see if I can find an universal & automatic solution.

    Regards.

    Thread Starter Ian Chapman

    (@ianchapman)

    That would be appreciated if there is a JS solution that could eliminate the form tags, so that the form will render as expected, but without any functionality when inside the Admin.

    I’ll use the workaround you provided for now, but would love to see such a feature added in the future.

    Thanks,
    Ian

    Thread Starter Ian Chapman

    (@ianchapman)

    Just a small note to anyone who comes across this code snippet – there is a small type in the code. The section to modify the Gravity Forms shortcode should be “gravityform”, not “gravity_form”.

            add_shortcode('gravityform', function(){
                
                echo '<div style="padding:50px 0; text-align:center; background:#f4f4f4;">Gravity Form</div>';
                
            });
    

    Otherwise the solution is working well for me.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Yeah, I didn’t know about the shortcode name (I don’t use Gravity Forms), so I just invented that one.

    For the JS solution, it could leads to some style issue if I delete/transform the <form> tag, since some CSS rules can target form .field. Anyways, I’ll try to find some time to work on it, see what I do.

    Regards.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Gravity Forms Shortcode Issue’ is closed to new replies.