View Full Version : checking fields

03-08-2007, 02:45 AM

I have a form that the user fills in details.
I want to make sure only numbers are in certain fields and letters in others.
I also want to make sure all fields are filled in before a user can continue.

What's the best way of alerting a user?
Are message boxes a good idea and how can these be done in php?


03-08-2007, 03:34 AM
Message boxes are not nearly as good as imbedding attractive "hints" for the user to please enter the right info. You can do this easily by imbedding PHP echo statements on the return trip from a form submit.

03-08-2007, 05:04 AM
There are many ways to do it.
if u want to do it with some javascript.then good.
I am not talking about to use java for validation just for popup error,
Bcoz when a user submits a form the fields will varified by the php validation
code ,if filed empty or letter or numbers problem, that popup msg comeout and when a user click ok, page will goback to previous page asking user to fill
in.(Note:this is automatically when user click on popup ok button).
Other u can use echo but for that the user will hit back button of the
browser to go back.(i think this is not better way to do this.).

I have some validation code in php and error msg with popup.
If required i will post for u.

03-08-2007, 09:56 AM
R u read my above post.

03-08-2007, 10:12 AM
i would really appreciate if you could post the validation code for me.Thank you

03-08-2007, 10:35 AM
This code is for letters:

if ( !preg_match('/^[a-zA-Z\" "]*$/', $name) )
error('Name is not Valid.\\n'.
'Please try again.');

This is for the numbers:

if ( !preg_match('/^[0-9\" "]*$/', $cleaned_for_sql['hp']) )
error ('HP Number is not Valid.\\n'.
'Please try again.');

Now save the following script as validate.php and include it as


function error($msg) {
<script language="JavaScript">
alert("<?php echo ($msg) ?> ");

I think this will help.

03-08-2007, 11:21 AM
thanks that's great!