Skip to content

Instantly share code, notes, and snippets.

@johnbocook
Created January 31, 2015 00:53
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 johnbocook/32097f80fe937b7616e3 to your computer and use it in GitHub Desktop.
Save johnbocook/32097f80fe937b7616e3 to your computer and use it in GitHub Desktop.
Takes parameters passed via URL and places them into Drupal 7 webform fields
/* Author Note:
* Captures URL parameters and inputs into Drupal webform
* Used for PPC Landing Page marketing. Passing SourceId, Adid, KwId to converted leads and submiting to database with lead.
* URL Ussage http://www.domain.com/?sid=Adwords&cmid=CampainID&adgid=AdGroupID&adid=AdID&kwid=KeyworkID
*/
//Split apart URL and extract Parameters
var parseQueryString = function() {
var str = window.location.search;
var objURL = {};
str.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) {
objURL[$1] = $3;
}
);
return objURL;
};
var params = parseQueryString();
//Takes KEY and VALUE from url and sets input value
function parmset(key) {
value = params["" + key + ""];
if (value === undefined) {
$('input[title=' + key + ']').attr("value", '');
} else {
$('input[title=' + key + ']').attr("value", '' + value + '');
};
};
function urlset(key) {
value = params["" + key + ""];
if (value === undefined) {
$('input[title=' + key + ']').attr("value", '');
} else {
$('input[title=' + key + ']').attr("value", '' + value + '');
};
};
// Fire URL Parm Functions
parmset('sid');
parmset('cmid');
parmset('adgid');
parmset('adid');
parmset('kwid');
/* Author Note:
* Takes url Pathname (http://www.domain.com/pathname/) and places into Drupal 7 webform 'Category' field.
* Used for a drupal 7 landing page framework to find which page converted the lead.
*/
//Grab Url Part and place in Category Field on Form
var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
var pathArray = window.location.pathname.split('/');
var subpage = pathArray[1];
if (subpage === '') {} else {
$('input[title=Category]').attr("value", '' + subpage + '');
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment