Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.