Advice | Find Links | Receive Links | Check Links | Find More Links

Javascript link form validation

Try it:
to http://www.sectorprime.com/
Result:

This is an easy-to-implement resource to allow you to provide your own on-the-form validation of links. The result is displayed client-side without a page reload - no installation of CGI scripts is required! You can see the validation in action above, and on our List Your Site page.

The validation typically works as follows:

  • An iframe contains the results of the validation check. This is created by calling a script at the SectorPrime web site, which returns a suitable message.
  • You can interact with the contents of the iFrame by javascript.
  • When your page is loaded, the validation iframe initially contains a 'waiting' message.
  • When the user enters the text field where they will type their link, javascript causes the validation message to be cleared.
  • When the user exits the text field, more javascript causes the validation to be performed, and a suitable validation message to be displayed.
  • The behaviour can be customised, including the contents of the validation messages.
  • You will need a link from your site to www.sectorprime.com - this is necessary to limit the bandwidth demands on our site.

To add the validation message iframe, add this to your page at the point at which you would like it to appear:

(obviously, replace <NAME OF FORM> with the name of your form, etc - don't forget to remove the angle brackets as well).

Then, on the text field which contains the link, add the following events:

onfocus="clearLinkValidation()" onblur="validateLink()"

Customisation

The snippets of HTML above are all you need to get going. However, to customise the behaviour, here are the possible ways of calling the script. Note that the simplest way to escape HTML and encode URLs is to use the javascript escape and encodeURI functions (view page source to see how I've done it).

Waiting

Default waiting message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?dowaiting=1

Customised waiting message (you provide the body HTML):

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?dowaiting=1&waiting=<ESCAPED HTML>

Redirected waiting message (you provide the URL):

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?dowaiting=1&waitingurl=<ENCODED URL>

Blank

Default blank message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?doblank=1

Customised blank message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?doblank=1&blank=<ESCAPED HTML>

Redirected blank message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?doblank=1&blankurl=<ENCODED URL>

Validation passed

Default validation passed message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >

Customised validation passed message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >&pass=<ESCAPED HTML>

Redirected validation passed message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >&passurl=<ENCODED URL>

Validation failed

Default validation failed message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >

Customised validation failed message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >&fail=<ESCAPED HTML>

Redirected validation failed message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >&failurl=<ENCODED URL>

Validation unavailable

This message is only shown if there is a problem with your link to www.sectorprime.com.

Default validation unavailable message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >

Customised validation unavailable message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >&unavailable=<ESCAPED HTML>

Redirected validation unavailable message:

http://www.sectorprime.com/cgi-bin/link_form_validation.pl?sectorprimelink=<... >&fromurl=<... >&tourl=<... >&unavailableurl=<ENCODED URL>

Accessing validation results with javascript

It's often desirable to access the results of the validation with javascript, for example to enable and disable the submit button. To do this, use the redirect customisations above, and then on your redirected pages you can use an onload event to interact with the parent frame, e.g.:

<body onload="parent.setReciprocalLinkOkay(true)">

if the reciprocal link has passed.

The redirected URL must be on the same site as your form in order for the browsers to allow them to interact, to prevent cross-site scripting. Then add some javascript to your form to handle the onload event:

You can see how we do this on our List Your Site page.

If you have any problems using this resource, or any suggestions on how it could be improved, please feel free to contact us.