Okay
  Public Ticket #2735276
Questions about using GET Parameters with Amelia's cutom fields
Closed

Comments

  •  2
    Polaris Media GmbH started the conversation

    How can we pass a URL-GET parameter to a custom field in Amelias booking form as plain text? E.g. we'd like to pass a plain text info inside an a-tag into a custom field inside Amelia's booking process like this:

    <a href="/amelia/booking.html?mycustomfield=Some%20Text">I want to collect this</a>

    Is this possible?

    Also, would it be possible to pass a price for a service the same way, or is it impossible to set a price dynamically?

    Best wishes

  •  2,572
    Aleksandar replied

    Hello there.

    This falls under custom work, so I can only offer some advice about this. Please take a look at this example:

    <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>

    It uses our JS hook to modify the value of first name and last name through URL, or to use our email notification placeholders in the URL.

    For example:

    https://localhost/ameliafull/index.php/booking/?firstName=John&lastName=Doe - this will add "John" in the First Name field, and "Doe" in the Last Name field.

    https://localhost/ameliafull/index.php/booking/?firstName=%customer_first_name%&lastName=%customer_last_name% this will add both the name and the last name of the customer, pulling it from our database if they're logged in.

    You can modify the JS to do something similar with custom field values. You can target the class "cf-ID".

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables