Problem with pre-populating of cons_email field

Options

I am new to convio. I created a survey and embedded it into a pagebuilder page, to allow constituents to sign up for "e-alerts." I added a pop-up script to the wrapper to enable users to start the process on one page (i.e., enter their email address), then click submit and complete the process on another page. This works fine the first time you do it. However, if you then go back to the form (or to another form), the email address field is populated with the web address of the referring page.

Any thoughts on what's going wrong here?

Thanks,

Wendy

Tagged:

Comments

  • Hi Wendy,

    Without intervention from a malfunctioning JavaScript, a Convio email address field should never be populated with a referring URL. Could you post the JavaScript that you're using in this thread? Watch out for script tags: this system eats them.

  • James Zetlen:

    Hi Wendy,

    Without intervention from a malfunctioning JavaScript, a Convio email address field should never be populated with a referring URL. Could you post the JavaScript that you're using in this thread? Watch out for script tags: this system eats them.

    Here is the script without the script tags:

    function prepop()

    {

    var url = '' + this.location;

    var idx  = url.indexOf('?');

    var query = "&" + url.substring(idx+1);

    var qs = query.toLowerCase();

    var key = "&cons_email=";

    var begin = qs.indexOf(key);

    begin += key.length;

    var end = qs.indexOf("&", begin);

    if (end == -1)

    end = query.length;

    var emailValue = unescape(query.substring(begin, end));

    if(begin == -1)

    emailValue = "";



    var txtBox = document.getElementById("cons_email");

    txtBox.value = emailValue;

    }

    window.onload = prepop;

  • Liz Murphy:

    Here is the script without the script tags:

    function prepop()

    {

    var url = '' + this.location;

    var idx  = url.indexOf('?');

    var query = "&" + url.substring(idx+1);

    var qs = query.toLowerCase();

    var key = "&cons_email=";

    var begin = qs.indexOf(key);

    begin += key.length;

    var end = qs.indexOf("&", begin);

    if (end == -1)

    end = query.length;

    var emailValue = unescape(query.substring(begin, end));

    if(begin == -1)

    emailValue = "";



    var txtBox = document.getElementById("cons_email");

    txtBox.value = emailValue;

    }

    window.onload = prepop;

    Hi Wendy,

    Looks like that JavaScript to get the query parameters is failing if those parameters don't exist. You know, if you're building this on a Convio page, you can use a Convio template tag to do this. The S334 tag will render the value of a URL parameter specified in the tag. Put it in code view!

    If the current URL is http://you.convio.net/site/PageServer?pagename=register&cons_email=devnull@convio.com

    then

    ]

    will render on the page as

    devnull@convio.com.

    You could put it in a JavaScript:

    document.getElementById('cons_email').value = ']';

    If this isn't on a Convio page and you don't have access to a server-side scripting language with global variables, you could use this JS function:

    function queryParameters(query) {

      var keyValuePairs = query.split(//g);

      var params = {};

      for (var i = 0, n = keyValuePairs.length; i < n; ++i) {

        var m = keyValuePairs.match(/^(+)(?:=(*))?/);

        if (m) {

          var key = decodeURIComponent(m);

          (params || (params = [])).push(decodeURIComponent(m));

        }

      }

      return params;

    }

    document.getElementById("cons_email").value = queryParameters(document.location.search);

    That should be more robust.

    Cheers

    James

Categories