Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

add cookie to remember data when enter in this php code .. Download validation.php . Try to use the cookies for the formin toremember the

add cookie to remember data when enter in this php code ..

Download validation.php . Try to use the cookies for the formin toremember the data entered into the field. Remember for 5 minutes. See if you can close your browser

and revisit it the page and have all of the prior settings for the checkerboard square be set. Try also using a different browser. Go to a different machine and see what happens (or have a frienda thenext lab PC workstation do so). Finally, wait more than 5 minutes to see if the page reverts back to its default settings.

---------- validation.php ------

if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } }

if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } }

if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } }

if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); }

if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } }

function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>

PHP Form Validation Example

* required field.

"> Name: * E-mail: * Website: Comment: Gender: Female Male *

Your Input:"; echo $name; echo " "; echo $email; echo " "; echo $website; echo " "; echo $comment; echo " "; echo $gender; ?>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

How autonomous should the target be left after the merger deal?

Answered: 1 week ago