SmartPORTAL: API and example populating the form using URL parameters

SmartPORTAL: API and example populating the form using URL parameters

SmartPORTAL has an API which allows you to hook into events.  This allows you to do a lot of different things as you can alter the form or form fields prior to the display of the form to the end user. 

The JavaScript function hook_profile_form_ready(profile) is called when the form is ready, If profile is null the user is not currently logged in, if they are logged in the profile will contain a full user record for them including email, name, address, phone etc.

Example: Populating a form using URL parameters

Scenario: You may have a signup form on your website home page which just asks for email address. Once completed the user clicks next and is taken to a more complete update form with their provided email address already added to that form. The link to the form could be something like:
https://[domain]/what-we-do/keeping-you-date/sign-up-for-updates?email=warren%40smartthing.org 

On the SmartPROFILE form page you could add the below script, this auto-populates the email address field in the form.

  1. <script>
    function getURIParameter(param, asArray) {
        return document.location.search.substring(1).split('&').reduce(function(p,c) {
            var parts = c.split('=', 2).map(function(param) { return decodeURIComponent(param); });
            if(parts.length == 0 || parts[0] != param) return (p instanceof Array) && !asArray ? null : p;
            return asArray ? p.concat(parts.concat(true)[1]) : parts.concat(true)[1];
        }, []);
    }

    function hook_profile_form_ready(profile) {
        var email =  getURIParameter('email');
        if (email) {
              $('[id="sp-email|address"]').val(email).change();
        }
    }
    </script>

    • Related Articles

    • SmartPORTAL: User login API features

      SmartPORTAL allows users to log in to your website using their Raiser's Edge NXT record. This means they can use the various SmartPORTAL forms such as login, profile updates, add action and the callhandler function. On top of this it also provides a ...
    • SmartCALLHANDLER: API and customisation

      You can customise SmartCALLHANDLER using our 'hooks' and the 'ST_API' function. Details of this are below. You require knowledge of JavaScript programming and the ability to add your code to the page where you have placed the SmartCALLHANDLER ...
    • SmartPORTAL - Set up instructions

      SmartPORTAL overview SmartPORTAL is a flexible, modular application that allows you to build forms based on your functional requirements. The core SmartPORTAL elements are: Profile update form Login / Register form Add Actions SmartPORTAL allows your ...
    • SmartSYNC: Real-time API security and requests

      SmartSYNC provides an API interface to run data flows in real-time and return the results to an external system. Using the API Enabling the API To enable the API you need to go to the Admin > Account page within your SmartSYNC account. Toggle the API ...
    • SmartPORTAL: Google form protection

      We provide support for Google Recaptcha v3 support on your SmartPORTAL forms. To enable, within the CORE settings of the product under the 'Security' tab enter your recaptcha keys. To create the keys you need to: ...