• Resolved Tory

    (@tmac187)


    I currently pass a set of default values to a CF7 form using a query string in the URL, ie., https://test.com/form?first_name=John&last_name=Smith. This works. But I would like to use a pop-up box on the current page to display the form instead of a separate page.

    Is there still a way to pass the default values to the form fields if I’m not sending the user to a different URL, but instead having a modal or box pop-up on the current page with the form?

    I’m open to any ideas or workarounds.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Tory

    (@tmac187)

    I found a way to pass them using data attributes.

    Can you explain how you achieve it??

    Thread Starter Tory

    (@tmac187)

    Sure. I used a link element that contained a data attribute, for example, data-city.

    <a data-toggle="modal" data-city="New York" title="Form popup" class="open-AddDialog" href="#addDialog">Click Here</a>

    When that link is clicked I use jquery to fire the pop-up.

    <script>
    jQuery(function($) {
        $(document).on("click", ".open-AddDialog", function () {
           var city = $(this).data('city');
           $(".modal-body #city").val( city );
        });  
    });
    </script>

    That piece of JS pops up a Bootstrap Modal with the Contact Form 7 shortcode in it. (Bootstrap is optional, I’m just familiar with it, and it made implementation easier for me. You’ll need to load the BS 4 library if you use the code below).

    <div class="modal hide" id="addDialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel">Form</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                    </div>
                    <div class="modal-body">
                        [contact-form-7 id="1" title="CF7 Form"]
                    </div>
            		<div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>

    Make sure you add an id to your CF7 field. Using the example above, I added id=city. You can do this in the form editor by adding id:city (or whatever you want your id to be) to the field: [text city id:city]

    Place all of the above on your page and when you click the link it should pop-up your CF7 form with the field pre-filled out with the text you put in the data- attribute in that link. In this case, it would fill out the City field in the form with New York.

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

The topic ‘Pass Parameters to Popup’ is closed to new replies.