[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Simple form validation with WBSP

Published on
8,963 Points
1 Endorsement
Last Modified:
Have you ever looked at the database of your registered users? If you do, you will find a lot of garbage data. Emails that does not exist, fake names and comments with spam or empty fields.

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:

<title>Feedback Form</title>
<form action="validation.wbsp" method="post">
<fieldset><legend>Enter your information in the form below.</legend><br />
First Name:<br/>
<input type="text" name="fname" size="20" maxlength="40" /><br /><br />
Last Name:<br/>
<input type="text" name="lname" size="40" maxlength="60"/><br /><br />
E-Mail:<br />
<input type="text" name="email" size="40" maxlength="60"/><br /><br />
Comments:<br />
<textarea name="comments" cols="40" rows="7"></textarea>
<div align="center"><input type="reset" />
<input type="submit" name="submit" value="Submit" /></div>

Open in new window

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:

[FormFields] WB_Required=email,fname,lname,comments
<title>Validate Form</title>
$wbif[$wbcstr[$wbv[email]|@]>1|Please insert your email address<br />|]
$wbif[$wblen[$wbgetv[email_array(0)]]>0||Your have inserted an invalid email format<br />]
$wbif[$wblen[$wbgetv[email_array(1)]]>0||Your have inserted an invalid email format<br />]
$wbif[$wblen[$wbgetvdomain(0)]]>0||Your have inserted an invalid email format<br />]
$wbif[($wblen[$wbgetvdomain(1)]]>1) and ($wblen[$wbgetvdomain(1)]]<5)||Your have inserted an invalid email format<br />]

Open in new window

We need to check 4 values (email,fname,lname,comments) if they are empty or not, then in case if they are empty we will give an error. We simply use one command, it is WB_Required which will check all the fields required, if one of them are empty it gives an error.

[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_to_2_Charactars_and_Numbers

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]|@]=1|| Please insert your email address<br />]

The IF:


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.

$wbif[$wblen[$wbgetv[email_array(0)]]>0||Your have inserted an invalid email format<br />]

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.


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.

$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.

Featured Post

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Join & Write a Comment

Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. In addition to the name of the font, it shows the font type and whether or not the font is embedded in the PDF f…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month