Knowledgebase

Article number: 301400

Hardcoded Forms in Sitekit

This article explains how to create a GUID, required for hardcoded forms in Sitekit.

We recommend that you use the Sitekit forms module whenever possible as the forms module will automatically create a "random" Globally Unique Identifier field that every form must have with a unique GUID for each submission.

If it is necessary to hard-code a form, the GUID needs to be created manually. This requires creating a "random" GUID with JavaScript.

The script goes in the "Page Head Section" and is called via an "onLoad" event handler on the opening <body> tag. This is shown in the table below. Values in bold can be changed if needed, but the code will work as it is. The values in bold must correspond otherwise the code will not work.

Code example

Page Head Section (Advanced Page Property)

The following code searches for the input field, creates a random GUID number called "g", gets the name of the field and then sets the field value to the value of the number "g".

<script>
function Fieldgrab(n, d) {
	var p,i,x;
	if(!d)
		d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		~ d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
		}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=AMSKgrab(n,d.layers[i].document);
	if(!x && document.getElementById)
		x=document.getElementById(n);
	return x;
	}

function makeGuid() {
	var g = "{";
	for(var i = 0; i < 32; i++)
		g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "")
	return g + "}";
	}

function setGuid() {
	var SetGuidField = Fieldgrab(GUIDField);	
	SetGuidField.value = (g);
	}
</script>

Body tag Advanced Page Property

In Page Properties > Advanced Properties > Access to BODY tag (advanced) add onload="makeGuid();setGuid()"

Form

In the hardcoded form add the following field which will be populated with the created "g" GUID value by the javascript.

<input type="hidden" name="GUIDField">

Related questions