The most basic approach you can use is manually validating each field and returning an error message if validation fails:
PHP Code:
<?php
if (isset($_POST['submit']))
{
$success = TRUE;
//Put each $_POST value into its own array
foreach ($_POST as $key => $val)
{
$$key = $val;
}
//Form validation starts here
if (empty($message))
{
$success = FALSE;
$message_error = 'The message field cannot be empty.';
}
if ($success == TRUE) redirect('/success_page.php');
}
?>
<form action="this_page.php">
<label for="message">Name:</label> <input type="text" name="message" id="message" value="<?=$message?>" />
<?php if (!empty($message_error)) echo $message_error; ?>
<br />
<input type="submit" name="submit" value="Send Message" />
</form>
There are loads of nice validation libraries available that will take care of the hard work for you. CodeIgniter is an MVC framework that has a great validation library - definitely worth checking out.