Introduction to Form Validators

What is a Form Validator?

Well a form validator checks the information that is about to be submitted via a form and decides whether the information should be submitted. It effectively judges the information based on a range of criteria that can be specified.

What criteria might you specify?

In the simplest case you may decide that there must be a value submitted for the ‘first name’ field in a form. So the form validator will check if the ‘first name’ field has a value in it, if it does then an action is performed such as a script being run that takes the form data and sends it in an email. If on the other hand the user has left the ‘first name’ field blank then the form validator will display some sort of error message and the script is not run.

download Cerberus

How do form validators work with HTML form?

JavaScript is the most commonly used client-side scripting language and this is generally used for such tasks as form validation. Here is a simple example of how form validation works:

An Example of the form validation process

An Example of the form validation process

Figure 1 Explanation

A user fills in the HTML form and then clicks the submit button. Once the submit button is clicked control passes to the form validator which checks whether the ‘first name’ field has a value in it, in other words whether it has been filled in. If the field has NOT been filled in the form validator returns ‘false’ and nothing further happens.

If the user fills in the ‘first name’ field a presses submit, the form validator in this instance returns ‘true’ to the HTML form and it carries out the appropriate action.

The example using HTML and JavaScript:

buy Forest Stream Tears of Mortal Solitude mp3


<html>
<head>
<title>A Contact Form</title>
<script type="text/javascript">
<!--

function validate_form()
{
    valid = true;

    if ( document.form.first_name.value == "" )
    {
        alert ( "Please fill in the 'Your Name' box." );
        valid = false;
    }

    return valid;
}

//-->
</script>

</head>

<body>

<form name="form" action="emailer.php" method="post" onsubmit="return validate_form();">
<h1>Please Enter Your Contact Details</h1> <p style="display:none"><a href="http://lavamp3.com/buy_mp3_album1920996/Maelo-Ruiz/Maelo.html">download Maelo mp3</a></p> 
First Name: <input name="first_name" size="20" type="text" />

Surname: <input name="surname" size="20" type="text" />

Tel: <input name="tel" size="20" type="text" />

<input name="send" size="20" type="submit" value="Submit Details" />
</form>
</body>
</html>

Leave a Comment

Hello world!

.!.

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!EL BOSSO and DIE PING PONGS download Komplett! album

Comments (1)

Extracting useful data from your Analytics cookies

As I discussed in my earlier blog post Analytics sets a number of cookies to track visitor interaction with your website. In this post I will show you how you can extract (and insert) useful data from one particular cookie: __utmz. Although I will just be focussing on this cookie, this principal is still the same for the other cookies.

As you may remember __utmz was the cookie that stores data about how a visitor arrived at your site. Here how you cna find your own example of the cookie data:

I generally use Firefox to check the cookie data as it makes it a whole lot easier than IE. To get to the cookie data just select: Tools>Options>Privacy>Show Cookies, then enter the name of your site e.g willmartinez.com.

Firefox cookie data

The important data to focus on from the image above is:

utmccn=(organic)|utmcsr=google|utmctr=motorcaravan+insurance|utmcmd=organic

As you can see all the variables I mentioned earlier are visible in a string of data, each variable separated by the pipe character |.

So what does this data tell us?

It tells us that I arrived at this site when I searched for ‘Motorcaravan Insurance’ on Google and then clicked on an organic search listing. Had I have arrived from a Yahoo organic search listing the data would have remained much the same and providing I searched using the same keywords only the utmcsr variable would have changed from Google to Yahoo.

What If I had arrived through a paid search ad?

Well, I will tell you but I would suggest trying this out for yourself and getting used to seeing the data first hand. Here’s an example:

utmcsr=Google|utmccn=(not%20set)|utmcmd=cpc|utmctr=motorcaravan+insurance

This shows I searched for Motorcaravan Insurance on Google then clicked the paid search ad and landed on the site. cpc refers to paid search or cost-per-click advertising. The utmccn variable is not set because this is not set automatically, you will have to append some variables to the end of your URL to set this, which I will now show you how to do.

Inserting data into the cookie variables

Inserting data is very simple. You just need to add the variable names and the values or data you want added to them at the end of the url.

e.g.

www.willmartinez.com/index.php?utmcsr=Affilliate&utmccn=aff_campaign&utmcmd=thewebsite.com&utmctr=none

To add variable data to be passed to a page you simple add the data after a ‘?’ in the sites URL. Then you write the variable_name=value any additional variable data is added by inserting an ‘&’ between them.

Accessing cookie data using Javascript

The two functions below work together to extract the data from your Analytics tracking cookies:


function getCookie(c_name)
{
if (document.cookie.length&gt;0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function getVariable(l,n,s) {
 if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
 var i,i2,i3,c="-";
 i=l.indexOf(n);
 i3=n.indexOf("=")+1;
 if (i &gt; -1) {
  i2=l.indexOf(s,i); if (i2 &lt; 0) { i2=l.length; }
  c=l.substring((i+i3),i2);
 }
 return c;
} 

buy Pest Hail the black metal wolves of belial LP mp3

The getCookie function takes a String as an argument which will be the name of the cookie and the function returns the contents of the cookie as a String.

This String can then be passed to the getVariable function which returns the value of the chosen variable.

Please note these functions should be called after the Analytics code in the page.

Here is a full example of a form which submits the details a user supplies as well as how they arrived at the site:


<html>
<head>
<title>Will Martinez’s Example</title>
<script type="text/javascript" src="/js/cookiefunctions.js"></script>
</head>
<body>

<form name="myForm" id="myForm" method="post" action="process.php">
<input type="hidden" name="Referer" id="Referer" value="" />
<p>name: <input type="text" name="name" /> </p>
<p>email: <input type="text" name="email" /> </p>

<input id="submit" type="submit" name="submit" value="SUBMIT" />
</form>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("xx-xxxxxx-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<script type="text/javascript">
var z = getCookie("__utmz");
var c = _uGC(z,"utmcsr=","|");
var d = _uGC(z,"utmcmd=","|");
var ref = c+" "+d;
document.getElementById('Referer').value=ref;
</script></body>
</html>

Leave a Comment

Google Analytics Cookies

Google Analytics uses cookies to track visitors and find out useful information about them. Information such as average time on site, pages viewed per visit and whether a visitor is new or returning are just some examples. Google Analytics sets 4 (officially 5) cookies when you land on a website (with its tracking installed), these are:

__utma

Essentially this cookie tracks:

    Secondhand Lions dvdrip

  • How many times a visitor has visited the site
  • The first time a visitor found your site.
  • A visitor’s last visit.

This type of cookie does not have an expiry date and is known as a ‘persistent cookie’ – Technically all cookies must have an expiry date, but the expiry date for this cookie is set to a few years, and as the cookies are reset every time a user arrives at the site it is safe to say that it has no expiry date.

__utmb &__utmc

These two cookies work in unison to calculate time spent on site. __utmb notes when the visitor arrives on the site and __utmc stores when the visitor leaves.
__utmz

This cookie stores information about how a visitor arrived on your site. Did they type in the URL directly into the browser? Have they come from an affiliate site? Or Did they come from via a search engine? The cookie stores a range of information in different variable, they are:

  • The campaign source (utmcsr) – e.g. Search engines like :Google, Yahoo, MSN, or another source like an affiliate site.
  • The campaign medium (utmcmd) – e.g. If we take for example a visitor arriving via a search engine – the campaign medium stores whether they came via an organic search result or paid search ad. If a user arrives directly this variable will be set to (direct) as well as the campaign source variable. The campaign medium mainly applies to search engines so that you can differentiate between paid/organic traffic but it can also be set for other uses – an example is if you have two links on an affiliate site then you may want to differentiate between visitors from each link and so you could set the variable accordingly. 
  • The campaign term (utmctr) - or keyword/search term. E.g. If I arrived via a search engine by searching for ‘will martinez’s blog’ then: utmctr = will martinez’s blog
  • The campaign content (utmcct) - used for A/B testing in paid search campaigns as you can pass an ads content straight into the cookie’s variable.
  • The campaign name (utmccn) - E.g. In Google Adwords the name of your ad campaign.
    utmgclid unique identifier used when AdWords auto tagging is enabled

__utmv 

If you are using the user-defined field for Google Analytics reporting then this cookie will be set with that value.

Leave a Comment

  
Email me at me@willmartinez.comWill Martinez.com , addon, , , , pranks, OpenSource.org, , Opera.com, , , , , , , , , , , , environnement, , , , , , Oracle.com, Oreilly.com, , , , , , , , ORNL.gov, , , , , , , , , OSTG.com, , OX.ac.uk, , , , , , , , , , , , , schematics, , PBS.org, , divertidos, , , ronald, , equivalent, , , davies, , Perl.com, , PHP.net, product, , severe, , groves, , , , phpBB.com, , Pitt.edu, , , , , treehouse, graveyard, , , , Plone.org, sexualidad, , , ,