Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1337597

    Hello,

    I have a website with individual product pages. On each of those pages there is a get a quote button. I want to link that button to a form page on my website that pre-selects the product on the from based on the page they are coming from. How do I create the link to add to the button so the form does that? (URL Parameters? How do I set it up? Do I need to add code? How do I create the URL Parameter link?)

    For example, a visitor is on https://metalcarport.com/2-car-metal-carport-kit-arizona/. When they click on the red button labeled “get a quote” above the accordion on the body of the page, it should redirect to the form page here: https://metalcarport.com/form-page-request-a-quote-carports-arizona/ but rather than having the field label “Select A Metal Carport Size” I want it to pre-select the option under it to “2 Car 4 Post” – the same option as the page they just came from. I want to create a link for each one of these fields.

    I’ve seen this made possible on other themes or sites that use URL parameters. I’m trying to achieve the same without having to create multiple forms for individual products. The closest answer I’ve seen to this on the net is here: https://www.jotform.com/answers/1349137-link-to-a-form-with-pre-selected-field

    Any help is appreciated.

    One last thing, my website keeps adding a / to the end of the url. Will this affect me using URL parameters?

    #1337842

    Hey Joseph,
    Thank you for your question and the link to your pages, please give this a try, on your page with the form add a code block element at the bottom with this javascript:

    
    <script>
    var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = decodeURIComponent(window.location.search.substring(1)),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;
        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : sParameterName[1];
            }
        }
    };
    
    var carportSize = getUrlParameter('size');
    
    if (carportSize != null) {
    	var val = carportSize;
         var sel = document.getElementById('avia_6_1');
          var opts = sel.options;
      for (var opt, j = 0; opt = opts[j]; j++) {
        if (opt.value == val) {
          sel.selectedIndex = j;
          break;
        }
      }
    }
    </script>
    

    Then on your page with the button make your link like this: your-site.com/form-page/?size=2%20Car%204%20Post the url parameter: ?size=2%20Car%204%20Post
    needs to match your option text for the correct option to be selected
    2022-01-29_005.jpg
    the spaces need to be replaced with &20
    2022-01-29_006.jpg
    If this doesn’t help please include an admin login in the Private Content area so we can be of more assistance.

    Best regards,
    Mike

    #1338087

    You are awesome!!! Thank you. This worked perfectly. I appreciate the help.

    #1338100

    Hi,
    Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Trying to create a link to a form with pre-selected fields based on from page’ is closed to new replies.