ArticlesReader.com Menu
Newest Articles
Most Viewed Articles
ArticlesReader.com RSS
Submit Article
Login
Signup
Search the articles

Articles Main Categories
Advice
Animals
Automobiles
Business
Career
Communications
Computer Programming
Computers
Entertainment
Environment
Family
Fashion
Finance
Food
Health & Medical
Home & Garden
Humor
Internet Business
Internet Marketing
Legal
Leisure & Recreation
Marketing
Other
Politics
Reference & Education
Religion
Self Improvement
Sports
Technology & Science
Travel
Writing
Subscribe
Receive alert message from us when new articles submitted to our site for free.

Enter your name

Enter your email

Syndicate

















Related Products
Home::CGI

PHP:Form Series, Part 1: Validators & Client-side Validation

Author : Dennis Pallett

Introduction Welcome to the first part of a new two-part series
on the PHP:Form web component. In this part, I will give you an
introduction to PHP:Form, its features, and why it is so useful.
I will also discuss the inbuilt validators that PHP:Form
supports. In the second part I will discuss the more advanced
features of PHP:Form.

What is PHP:Form? PHP:Form is a (new) web component, developed
by TGP PHP Scripts (http://phpscripts.pallettgroup.com). It is
designed to help you create forms with a lot less effort. When
you're creating a new PHP script, you will undoubtedly have to
create forms to allow input to be entered. There is (almost) no
PHP script without forms, and forms usually require solid
validation to make sure there are no security leaks. It would be
nice if those forms are accessible as well, but this often gets
forgotten.

We've all had to create forms again and again. And every time
we've had to write those validation functions. I'm sure you
remember... if (empty($blah)) { echo 'Invalid'; }, etc. After a
while it becomes a really boring and mundane task, and most of
the time we don't do it properly either. One of the hardest
things to do is to return error messages, indicating what is
wrong, and allowing visitors to fix their mistakes, without
having to re-do the complete form. I used to simply tell them to
hit the back-button, after returning the errors, but this is
obviously a not-so-good way of doing it.

Thankfully, that's where PHP:Form steps in. It handles all the
boring parts for you, and does it properly as well.

PHP:Form has support for inbuilt validators, which means you
only have to use a simple HTML-like syntax to add new validation
logic to a form. With these validators also comes automatic
client-side validation. All the necessary JavaScript is created
for you, and there's nothing you need to do. Another remarkable
feature of PHP:Form are so-called "formtypes", which are
basically form templates. These allow you define form templates,
which can be re-used over and over again.

Let's have a closer look at the validation part of PHP:Form; the
validators.

Inbuilt Validators & Client-side Validation Before we look at
the validators, let's first look at the basic PHP:Form syntax.
It has a really simple syntax, because it's basic HTML. To
create a new form, use the tags, like so:

 	... form html goes here ...	


That's all that is really necessary. But you must also tell the
form to display, using PHP, like so:

$_FORMS->display ('example');

Those two things are the only things absolutely necessary to
create and display a new form. Of course, nothing will be
displayed yet because you haven't created any input fields. To
see a simple form in action, have a look at demo 1
(http://www.phpit.net/demo/phpform%20series/demos/demo1.php)

Let's move on to validators now. Validators are used to validate
form fields, and just like the form tags, they are simple html,
for example:

Your error message
here


You can either place validators in between the form tags, or
outside the form tags. If you place them outside the form tags
you must specify the form name (using the 'form' attribute).

A simple form with a validator would look like this:


// Include PHP:Form include ('../phpform.php');

// Begin form: ?>

required="true">

Please
enter your name



Name: value="Go!" />


validate ('example') == true) { // Show
POST'ed values echo '
'; 	print_r ($_POST); 	echo '
';
} else { // Display form $_FORMS->display ("example"); } ?>
View live demo
(http://www.phpit.net/demo/phpform%20series/demos/demo2.php)

As you can see in the code we created a validator that has the
required attribute set to "true". That means that this validator
just checks whether the value of the input field isn't empty.

There are 5 different kinds of validators: - Required: they are
used to make sure an input field isn't empty, like I just
demonstrated.

Please fill in
something


- Numeric: they are used to make sure an input field only
contains numbers, and nothing else.

Please fill in
something


- Regex: they can be used to specifiy a regular expression that
an input field must match.

Please enter 'test'
only.


- Callback: callback validators can take a callback function
that is run on the server-side. That callback function is passed
the value of the input field, and the function must return true
or false. This is used for really advanced validation (and it's
likely you will hardly ever use the callback validator)

Not a valid
e-mail address.validator>


- Name: name validator can be used to display a message or error
only when you want to. They can only be shown when you manually
show them using the trigger_error ('form', 'errorname') method.

This is my custom
error!


Then in PHP: trigger_error ('example', 'mymsg');
?>

When using validators, you will probably want to check if a form
validates or not. To do this, use the validate() method, as seen
in demo 2:

If ($_FORMS->validate('example') == true) { echo 'It
validates!'; } else { echo It 'doesn\'t validate!'; }

Client-Side Validation PHP:Form also automatically generates
client-side validation (JavaScript) when using validators. It
natively supports the required, numeric and regex validators,
but it doesn't (fully) support the callback validator. This
isn't really possible either, because the callback validator
points to a function on the server-side. But if you create a
JavaScript function with the same name as the callback function,
it will work, and it will run the JavaScript function you
created. This gives you great power, and means you can even
using advanced JavaScript functions and Ajax to validate data.

If you would like to see the client-side validation in action,
have a look at demo 2 again, and make sure you have JavaScript
enabled. You will probably notice how fast the errors are
returned, and that no refresh happens at all. That's the
client-side validation.

Conclusion In this first part of the PHP:Form series I have
shown you what PHP:Form is: an extremely neat PHP form
component, that is really useful for building web forms. I have
been using it myself now for a few months, and I still can't get
over how great it is. It has really simplified things, and I can
focus on the important stuff. If you're still in doubt, have a
look at the PHP:Form product page for more information and
demo's (http://phpscripts.pallettgroup.com/phpform/?ref=phpit).

I have also shown you exactly what validators are, and the
different types. Validators are the most important part of
PHP:Form, and you will probably use them in every form. You can
some really interesting things with them, and when you combine a
few validators it's possible to create a extremely secure form.

In the next part I will have a look at "form types", the form
templates of PHP:Form. I will also have a look at setting
default values, using the set_value() method of PHP:Form.

If you're interested in purchasing PHP:Form, don't forget to use
the special PHPit coupon code: phpit PHP:Form product page
(http://phpscripts.pallettgroup.com/phpform/?ref=phpit)

Spam emails More free articles

Related articles


  1. 5 CGI Scripts You Must Use to Turn Your Site Into a Powerhouse
  2. Clever Profit Growth Software
  3. Why Aren't You Using CGI
  4. Use CGI to Automate Your Web Site
  5. CGI: What the Heck Is That?
  6. CGI Security Issues
  7. How to Stop Digital Thieves with CGI
  8. Quick Intro to PHP Development
  9. Better Writing: What Works and What Doesn't
  10. Password Protection and File Inclusion With PHP
  11. Autoresponders With PHP
  12. Track your visitors, using PHP
  13. PHP On-The-Fly!
  14. PHP and Cookies; a good mix!
  15. Screen scraping your way into RSS
  16. Mastering Regular Expressions in PHP
  17. ASP, CGI and PHP Scripts and Record-Locking: What Every Webmaster Needs To Know
  18. Open Source Scripts
  19. this is a test
  20. An Extensive Examination of the PHP:DataGrid Component: Part 1
  21. PHP:Form Series, Part 1: Validators & Client-side Validation
  22. Design an Online Chat Room with PHP and MySQL
More related feeds
PHP:Form Series, Part 1: Validators and Client-side Validation
Introduction Welcome to the first part of a new two-part series on the PHP:Form web component. In this part, I will give you an introduction to PHP:Form, its features, and why it is so useful. I will also discuss the inbuilt validators ...

Ajax Web Aplicationz & CooL web SCRiPTS - PART 2
One ideal use of this is data validation. Validate your forms on the client to provide instant user feedback, and once the form is successfully submitted, validate it again on the server to ensure its integrity, using the exact same ...

100+ Resources for Web Developers
A 16 part series on how to build a WordPress theme from whoa to go. 101. Highlight Author Comments Matt Cutts shows you how to change the color of your own comments so they stand out. For WordPress ...

PHP:Form Series, Part 1: Validators & Client-side Validation
In this first part, of a new two-part series, Dennis Pallett has a look at the PHP:Form component. He first discusses the component, and its features. He then has a deeper look at the inbuilt validation of PHP:Form, called validators, ...

Frontpage 2003 google analytics. Google analytics integration (roi ...
Finds synonyms (fri aug -: 51: pdt) new google search web analytics (wed jan -: 23: pst) rss validator ms office sbe and frontpage eval kits. Microsoft office frontpage allows a web page designer to add a browser to the list you can ...

18 new messages in 10 topics - digest
PHP form accepts input from a user, then passes these as arguments to > > > a configurable shell script or OS command. I would like for the > > > output generated from the shell script/command shall be displayed in a ...

26 new messages in 19 topics - digest
1 of 1 == Date: Thurs, Jun 19 2008 1:23 pm From: "r_tist". If the site works well, loads quickly for client base and is fully functional + generates new business, then I don't see what this issue with validation is? ...

me and emily that really work!
bill validators jab archives anissina peizerat video tom wassel sapphic real clips magic school bus videos star wars wav files web messe wifes real video to avi jato free pc to phone international call sitemap movie pass puff puff ...

Imagine Yourself afb map scott
active series 7 and 63 licenses in nys alaska airlines reservations advent angel one winged sitemap inspirational saying about mother sitemap lunch video.com sitemap sex orgy clorazepate jaws unleashed torrent playa linda pirate ship ...

 


 

© 2007 articlesreader.com - All Rights Reserved