Last active
December 22, 2016 15:27
-
-
Save toddheslin/3b8b51d3d48e4568af09 to your computer and use it in GitHub Desktop.
Setting url params as variables in Wufoo embed form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| // The following code is from @dorward answering a stackoverflow question. | |
| // Like the Wufoo embed, it doesn't rely on jQuery. Thanks @dorward! | |
| var QueryString = function () { | |
| // This function is anonymous, is executed immediately and | |
| // the return value is assigned to QueryString! | |
| var query_string = {}; | |
| var query = window.location.search.substring(1); | |
| var vars = query.split("&"); | |
| for (var i=0;i<vars.length;i++) { | |
| var pair = vars[i].split("="); | |
| // If first entry with this name | |
| if (typeof query_string[pair[0]] === "undefined") { | |
| query_string[pair[0]] = pair[1]; | |
| // If second entry with this name | |
| } else if (typeof query_string[pair[0]] === "string") { | |
| var arr = [ query_string[pair[0]], pair[1] ]; | |
| query_string[pair[0]] = arr; | |
| // If third or later entry with this name | |
| } else { | |
| query_string[pair[0]].push(pair[1]); | |
| } | |
| } | |
| return query_string; | |
| }(); | |
| // for this part down, best to copy the script from your wufoo admin panel however pay close attention to the if statement below and the defaultValues in the first 'if code block' | |
| var z7zupww0vb98kb; | |
| (function(d, t) { | |
| // ensure you update 'first' and 'last' with the variables you are looking for in the URL. Change this expression if you require more variables to be present before you load the default Values in | |
| if (window.location.search === ""){ | |
| var s = d.createElement(t), options = { | |
| 'userName':'######', //this is your username for Wufoo | |
| 'formHash':'######', //this is your form hash from wufoo | |
| 'autoResize':true, | |
| 'height':'540', | |
| 'async':true, | |
| 'host':'wufoo.com', | |
| 'header':'hide', | |
| 'ssl':true, | |
| //replace 'first' and 'last' with the names of the params within your url | |
| 'defaultValues':'field1='+QueryString.first+'&field2='+QueryString.last}; | |
| } else { | |
| var s = d.createElement(t), options = { | |
| 'userName':'#####', // same as above | |
| 'formHash':'#####', // same as above | |
| 'autoResize':true, | |
| 'height':'540', | |
| 'async':true, | |
| 'host':'wufoo.com', | |
| 'header':'hide', | |
| 'ssl':true}; | |
| }; | |
| s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'www.wufoo.com/scripts/embed/form.js'; | |
| s.onload = s.onreadystatechange = function() { | |
| var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return; | |
| try { z7zupww0vb98kb = new WufooForm();z7zupww0vb98kb.initialize(options);z7zupww0vb98kb.display(); } catch (e) {}}; | |
| var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr); | |
| })(document, 'script'); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment