954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP: Form Validation

Hey there all. I wanted to know if there was a way to use php to validate form.

Well in more detail, I wanted to know if it was possible to print a msgbox using php telling the user he has missed some thing rather than having to display a new page. Also I don't want to use javascript if possible. Would like to thank in advance.

krea2r
Newbie Poster
14 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Of course there is. This is basic PHP. Have you tried to write code for this yet?

stymiee
He's No Good To Me Dead
Moderator
3,360 posts since May 2006
Reputation Points: 161
Solved Threads: 38
 

Hi,

Whats so bad in displaying the form again? If a input field is empty, you just give it a value like value="Please fill out this field". I think most sites do it like that, and message boxes without JavaScript are hardly possible.


Michael

pcschrottie
Posting Whiz in Training
204 posts since Dec 2004
Reputation Points: 11
Solved Threads: 8
 

If you wanted to use php functions to do the validation (say against database entries and such), then you might want to consider using an ajax library such as xajax, and make it look spiffy using something like scriptaculous (ok, maybe I'm going overboard, but it can be very slick). I've used that to validate form fields against a database, and point out where issues might exist.

But, you can't really get away from javascript, if you don't want the page to reload. PHP is a server side language, meaning that once the form is rendered and sent to the browser, there's NO link with the server again until you submit back (or use ajax like stuff).

Personally, I prefer just doing client-side javascript validation, as its easier to point out to the user where errors lie. That's not to say that you don't need to revalidate once you hit php, as the javascript side is easily forgeable.

MCP
Light Poster
44 posts since Oct 2006
Reputation Points: 14
Solved Threads: 3
 

Thanks a lot guys for your help. I think i will stick with the form being reshown for the moment till i get a little more grisps with this php. THANKS A LOT AGAIN.

krea2r
Newbie Poster
14 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

I wanted to know if there was a way to use php to validate form.

Well in more detail, I wanted to know if it was possible to print a msgbox using php telling the user he has missed some thing rather than having to display a new page. Also I don't want to use javascript if possible.

er.amitkatoch
Newbie Poster
1 post since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Hey there all. I wanted to know if there was a way to use php to validate form.

Well in more detail, I wanted to know if it was possible to print a msgbox using php telling the user he has missed some thing rather than having to display a new page. Also I don't want to use javascript if possible. Would like to thank in advance.

I wanted to know if it was possible to print a msgbox using phpvalidation must be in php

vinothkumar023
Newbie Poster
2 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

I have been trying to put validation using JavaScript
Is there any one to help me out

me.friend
Newbie Poster
1 post since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

here is small example how to print validation msg in php

<?
if(isset($_POST['submit'])) // after submit
{
  $username = trim($_POST['username']); // remove white spaces from value.
if($username=='') // if username is blank
{
    $error = 1;
}
}
?>
<html>
<body>
<div id=msgbox><? if($error==1)echo "username cant be blank"; ?></div>
<form method='post'>
<p>username <input type="text" name="username"></p>
<input type="submit" name="submit">
</form>
</body>
<html>
sam023
Junior Poster
164 posts since Jun 2009
Reputation Points: 11
Solved Threads: 6
 

[code=php]
if($_REQUEST['username'] == ''){
$error[] =

jaini817
Newbie Poster
1 post since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You