Skip to content

Instantly share code, notes, and snippets.

@emwiles
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emwiles/dd90f12f9766765f929b to your computer and use it in GitHub Desktop.
Save emwiles/dd90f12f9766765f929b to your computer and use it in GitHub Desktop.
Autopopulate a form field from an email URL
Email hyperlink: http://mysite.com/?fieldID1=AutopopulateA&fieldID2=AutopopulateB
Landing page fields:
<table cellpadding=0 cellspacing=0 >
<tr><td style="padding: 5px 0px 0px 5px;">
<div style="position: relative; width:250px;" id="fieldID1"><div style="width: 250px;"><div class="fieldLabel" style="width: 250px; margin: 5px 3px; "><span style="color:#265b80; font-family: arial font-size: 12pt"><strong >Field One:<span class="required">*</span></strong></span></div></div><input type="text" name="Field One" id ="fieldID1" label="Field One" class="textInput defaultText" style="margin: 0 3px 5px 3px; height: 20px; width: 200px;"></div></td>
<td width="40px">&nbsp;</td>
<td style="padding: 5px 0px 0px 5px;">
<div style="position: relative; width:200px;" id="fieldID2"><div style="width: 200px; "><div class="fieldLabel" style="width: 200px; margin: 5px 3px; "><span style="color:#265b80; font-family: arial font-size: 12pt"><strong >Field Two:<span class="required">*</span></strong></span></div></div><input type="text" name="Field Two" id ="fieldID2" label="Field Two:" class="textInput defaultText" style="margin: 0 3px 5px 3px; height: 20px; width: 200px;"></div></td>
</tr>
</table>
Landing page Javascript (add before </body>):
<script>
var fieldID1 = "";
var fieldID2 = "";
fieldID1 = getParameterByName('fieldID1');
fieldID2 = getParameterByName('fieldID2');
if (fieldID1 != -1){
document.getElementById("fieldID1").value = fieldID1;
}
if (fieldID2 != -1){
document.getElementById("fieldID2").value = fieldID2;
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment