How do I make a website field mandatory?
First, it is a good idea in your HTML to say which fields are mandatory or not, for instance by marking them with a '*' by them.
Then you do the check in your PHP code after the form has been submitted. So let's say we have a field called 'mandatory' and the form was submitted by post, here is how we can check for a value:
<?php
$anyvalue = $_POST[mandatory];
if(!$anyvalue) { echo "No value - please go back and fill in"; }
//don't use if you want '0' to be a valid value
//a better test for the variable to have some contents
$length = strlen($anyvalue);
if(!$length) { echo "No value - please go back and fill in!"; }
?>
More forms PHP Questions
How do I know if magic quotes is switched on?How do I check that a valid email address is entered?
What are magic quotes?
How can I access information sent through POST on a form?
How do I remove HTML tags from a string?