Jump to content

PHP validation of HTML forms


mkurtis

Recommended Posts

I am trying to create a php script that will validate the information entered in a HTML form.  If the forms are empty, I would like the user to be given the same screen again, with the incorrect forms highlighted, like in red or something. When the user actually enters the correct information, I would like it then to call a different function that would write to a database.  I don't know how to keep returning the page if the information is incorrect, however.  Here is what I have for the initial form:

<?php
include('database.php');
if (isset($_GET['submit'])) {
	validate();
} else{
?>
<body>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="GET">
Name<br><input type="text" value="" size=40 name="name"><br>
Address<br><input type="text" value="" size=40 name="address"><br>
City<br><input type="text" value="" size=15 name="city">
<input type="submit" value="Next" size=14 name="submit">
</form>
</body>
<?php
}
?>

Where database.php would contain the function validate, and also the database function. I really only need to know how to write the validate function.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/55530-php-validation-of-html-forms/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.