Okay
  Public Ticket #2687094
Autofill Form with Query
Closed

Comments

  • Julien Schürer started the conversation

    Hello,

    is it possible to autofill a amelia booking form with a link with a query.

    For example: www.test.com/?firstname=Peter

    So that the field first name gets auto filled with the name Peter.

    Thank you very much

    Julien

  • [deleted] replied

    Hello Julien, 

    Thank you for your purchase.

    Yes, you can try using this script for achieving that:

    <script>
      var getUrlParams = function (url) {
        var params = {};
        var parser = document.createElement('a');
        parser.href = url;
        var query = parser.search.substring(1);
        var vars = query.split('&');
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split('=');
          params[pair[0]] = decodeURIComponent(pair[1]);
        }
        return params;
      };
      window.urlParams = getUrlParams(window.location.href);
      window.beforeConfirmBookingLoaded = function () {
        var firstName = document.querySelector("#am-confirm-booking > div:nth-child(1) > form > div.am-confirm-booking-data.el-row > div:nth-child(3) > div > div > div > input");
        var lastName = document.querySelector("#am-confirm-booking > div:nth-child(1) > form > div.am-confirm-booking-data.el-row > div:nth-child(4) > div > div > div > input");
        if ('firstName' in window.urlParams) {
          firstName.value = window.urlParams.firstName;
          firstName.dispatchEvent(new Event('input'));
        }
        if ('lastName' in window.urlParams) {
          lastName.value = window.urlParams.lastName;
          lastName.dispatchEvent(new Event('input'));
        }
      }
    </script>
    https://localhost/ameliafull/index.php/booking/?firstName=John&lastName=Doe

    If you have any other questions or concerns feel free to open a new ticket and we will gladly help out.