All Javascript needed for this script is placed in a single file in this directory name SimpleContactForm.js
Below you will find a description of each part of this file;
this information is intended for anyone who wants to modify the script and is not needed for installation.
All functionality is wrapped in a single class : SimpleContactForm
.
A new instance of this class is created for each form that is added to a page.
A new instance is automatically called by the script after any form is created.
This class takes six parameters :
Function | Attributes | Description |
---|---|---|
addClass | private static |
Adds a CSS class to an element without overriding existing classes.
|
addListener | private static |
This utility function registers an event listener to the given element.
|
createElement | private static |
Creates an HTML element of the specified type with the given attributes.
|
fieldGetInput | private static |
Returns a SimpleContactForm.FieldResult object representing the field with the given name.
|
getElementsByClass | private static |
Returns all elements with a matching class attribute.
|
removeClass | private static |
Removes a CSS class from an element.
|
removeListener | private static |
This utility function removes an event listener from the given element.
|
stopEvent | private static |
This function cancels an events default behaviour.
|
stripHTML | private static |
This function will strip all HTML tags from a string and compress all white space.
|
trim | private static |
Strips the whitespace from the beginning and end of a string
|
validateEmail | private static |
Performs a very simple check to validate an email's format. This function cannot guarantee that the email exists.
|
validateURL | private static |
Performs a very simple check to validate a URL's format. This function cannot guarantee that the URL exists.
|
SimpleContactForm | private |
Creates a new SimpleContactForm instance.
|
getString | private |
Returns a string from this script's string definitions.
|
eventInputBlur | private |
Called when the focus on a fields input is lost. Removes the CSS focus class
and hides the validation error popup.
|
eventInputFocus | private |
Called when the a fields input gains focus. Adds the CSS focus class
and shows the validation error popup.
|
eventInputLimitAlphaNum | private | Called when a character is entered on a fields input and limits the range of characters allowed to only letters and numbers. |
eventInputLimitNumbers | private | Called when a character is entered on a fields input and limits the range of characters allowed to only numbers. |
eventRadioGroupSelect | private | Added to radio buttons. This function will remove validation errors associated with a radio group when one is selected. |
eventRefreshVerificationImage | private |
Added to the <a> tag when the form is created this function will reload the
verification/captcha image. The form must have an <a> tag defined with the same id as the
image element appended with '-refresh' eg. <a id="IMAGE_ID-refresh"></a> .
|
eventValidateForm | private |
Called when the form is submitted. This will then call the validate function.
|
validate | private | This function is automatically called when the form is submitted. The form will only be submitted once all fields have been validated. |
The FieldResult
class wraps a fields input element. Used to transparently work with a single input
(text field, text box, etc) or multiple input (radio groups etc.)