Jump to content

Oscar11

Members
  • Posts

    2
  • Joined

  • Last visited

Oscar11's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I am new to this and have a form which requires the user to fill in if they are over 19. My question is, should I use a radio box. The user has to tick the box to prove they are an adultl, I want this to allow the user to complete the form. If the user is under 19 then they have to filli n a different form. How do I redirect them to the other form? I have had a go at this for the php script: {if {$under19Err = "Please complete client form";} else { //not sure what else to put. This is the coding for the checkbox: <input type="radio" name="over19"> <?php echo $under19Err;?>) <span class="style8">Tick to confirm you are over 19</span>
  2. I took this from your php form tuition. It's asking for empty fields but as I have <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> where the email address that I want the form to be set to is. Where do I put the address? <!DOCTYPE HTML><html><head><style>.error {color: #FF0000;}</style></head><body><?php// define variables and set to empty values$nameErr = $emailErr = $genderErr = $websiteErr = "";$name = $email = $gender = $comment = $website = "";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 syntax is valid if (!preg_match("/([w-]+@[w-]+.[w-]+)/",$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;}?><h2>PHP Form Validation Example</h2><p><span class="error">* required field.</span></p><form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"></form></body></html>
×
×
  • Create New...