Is there a way to pre-fill an order form?

So if anyone wants to use our JavaScript feel free… however no Warranty provided…so you’ll need to test / support it in yourselves.

Disclaimer aside, we’re able to drop this into the HTML Header area on the OrderForm Theme customization and get the Query String processing discussed in this thread (i.e. pre-fill the PromoCode based on URL Encoded parameters.

<script>
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}
</script> 


<script type="text/javascript">  
    jQuery(document).ready(function () {
    var promo_code = getParameterByName('inf_field_PromoCode');
    if (promo_code && promo_code.length > 0) {
      jQuery('#promoCode').val(promo_code);
    }
    var url = window.location.href;
    var regex = new RegExp("\/app\/orderForms\/([^\/\?]+)");
    var results = regex.exec(url);
    if (results && results[1]) {
      var order_form_id = results[1];
      Infusion.Ecomm.OrderForms.ajaxSubmitForm('orderForm', false, 0, 0, order_form_id, 'RENDER_ORDER_FORM', ['ORDER_FORM_PRODUCT_LIST', 'ORDER_FORM_SUMMARY', 'UP_SELLS', 'PAYMENT_PLANS', 'SHIPPING_OPTIONS']);
    }
  });
</script>

A few notes:

  • The PromoCode in the URL must be inf_field_PromoCode

  • It extracts the Form Name from the “vanity” url provided in the “Links” section of the OrderForm configuration… so the “Nice Readable URL” …

  • This also assumes the OrderForm Theme …is pretty standard across all the InfusionSoft options… It’s possible one of the themes does not use the same form field identifiers and stuff, so the jQuery might break down…but assuming all the InfusionSotf themes are pretty standard, this should work.

Otherwise this is pretty generic JavaScript …

1 Like