Hi,
I got simple form with name , address and other details. I dont want to use javascript for field validation. I want to use PHP for validation. How I should do this. I mean I should have seperate PHP file on the server that check each field and if there is any filed empty then it should present user with a same page indicating missing filed. Or should I do it on same page. Please let me know which is the best way and give me a small example if you can so that can help me.
Thanks
Form Validation
Moderator: General Moderators
- seppo0010
- Forum Commoner
- Posts: 47
- Joined: Wed Oct 24, 2007 4:13 pm
- Location: Buenos Aires, Argentina
The usual thing is to use the same page as action, so you can show the user the form and the errors and a chance to fix it...
Code: Select all
<?php
if (count($_POST) > 0)
{
if (validation())
{
dosomething();
header("location: everythingok.php"):
exit;
}
else {
$error = 'Name is required';
}
}
//....
?>
...
<?php if (isset($error)) echo '<p>' , $error , '</p>'; ?>
<form action='thispage.php' method='post'>
...
</form>seppo0010 wrote:The usual thing is to use the same page as action, so you can show the user the form and the errors and a chance to fix it...
Code: Select all
<?php if (count($_POST) > 0) { if (validation()) { dosomething(); header("location: everythingok.php"): exit; } else { $error = 'Name is required'; } } //.... ?> ... <?php if (isset($error)) echo '<p>' , $error , '</p>'; ?> <form action='thispage.php' method='post'> ... </form>
Thanks very much