Friday, June 8, 2018

How to include url in modal webform - Javascript method

Modal webforms will always include the url of the webform but not the url of the parent page.
1. Add a new field to the webform, this field will take the value of the url, in this example it is called "From Page"
2. You can grab the url value using Jquery:
// get current page from url and assign value to field
        var msgurl = $(location).attr('pathname');
        var str = "foo/bar/test.html";
        var lc = msgurl.lastIndexOf('/');
        var pmodel = msgurl.substring(lc + 1);
        $('.get-more-info #edit-submitted-from-page').val(pmodel);

3. Hide the field with CSS (display: none;)

No comments:

Post a Comment