In this tutorial I will show you how to make a simple validation form using WhizBase. With it you cannot control and validate everything, but at least you will filter some data. It will teach you some basics and it will save you a lot of deleting work.
The boring part
The most boring part for a developer is HTML, generally programmers and developers do not like designing. If you ask me, I hate HTML coding, I mostly give it to my wife, she likes it and I work on the more complicated things «Server Side Scripting».
Let us make a file named as «form.htm» and put in it the next code:
Pay attention to the action attribute in the form tag, we will send our data to validation.wbsp which is our WhizBase Server Pages file.
The Need For Speed Part
Have you ever played Need For Speed, I like the Lamborghini car, that is a great game. WhizBase is something like that to other languages when you are developing a site. You do not need a lot of time to create it.
Let us create the file validation.wbsp and put WhizBase code in it:
We need to check 4 values (email,fname,lname,comment
[FormFields] is a command where we tell the server to start processing essential data for WhizBase file, and we close it with <!--WB_BeginTemplate--> command.
When we come to email validation we need to validate its format also, it is important if it is in the format of:
Charactars_and_Numbers@ Charactars_and_Numbers.4_t
From this we need to check:
* does it have @ symbol, and only once.
* Before @ symbol we need to have at least 1 character
* Do we have a dot in the second part which we split with it the rest to two parts.
* The first part must be at least one character
* The second part must have at least 2 characters and at most 4
Let us start playing cards.
First we need to check if there is and only one @ symbol in the email, if it is false we give an error. This is done with if statement and wbcst function.
$wbif[$wbcstr[$wbv[email]|
The IF:
$wbif[ CONDITION | IF TRUE | IF FALSE]
The CONDITION:
$wbcstr[ STRING | STRING TO LOOK FOR] = 1
In WhizBase get and post methods are considered the same, if you send a variable using post method or send it using get method all the variables are created on the fly as a special set.
Considering that we will just get these variables with $wbv[var_name].
The STRING: $wbv[email]
Second we split the email address to two parts and put it in an array, then we check the first part if it is at least 1 character.
$wbsplit[$wbv[email]|email
$wbif[$wblen[$wbgetv[email
We notice WBSPLIT function, it takes a string and an array name and a separator, creates the array and fill the string's part separated by the separator.
$wbsplit[ STRING | ARRAY_NAME | SEPARATOR]
In the second line we get the length of the first part by using WBLEN and check if it is more than zero characters.
$wblen[ STRING ]
To access a variable we need to use the WBGETV function which accesses variables and arrays, and we call the first part of the array with (0) - in WBSP 0 is the first element in the array.
The STRING:
$wbgetv[ VARIABLE_NAME ]
Third we make the same process to the other part with the dot, and we have a simple email validation done.
For more information email me at: NurAzije [at] Gmail [dot] com
Or visit WhizBase official site at www.whizbase.com
NurAzije is a PHP and WhizBase programmer, who at the time of article publication is working in partnership with WhizBase on several projects.