mkurtis Posted June 14, 2007 Share Posted June 14, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/55530-php-validation-of-html-forms/ Share on other sites More sharing options...
trq Posted June 14, 2007 Share Posted June 14, 2007 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. Honestly, this is much better done in Javascript. PHP runs on the server so will require an extra request to the server. Quote Link to comment https://forums.phpfreaks.com/topic/55530-php-validation-of-html-forms/#findComment-274391 Share on other sites More sharing options...
mkurtis Posted June 14, 2007 Author Share Posted June 14, 2007 Do you know of any resources that would detail how to accomplish the same thing with javascript? Quote Link to comment https://forums.phpfreaks.com/topic/55530-php-validation-of-html-forms/#findComment-274396 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.