Jump to content

Search the Community

Showing results for tags 'required'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 3 results

  1. If you use <input required> how do you stop it from allowing just spaces and how do you make sure there is a minimum entry of 8 non spaces. Thanks
  2. i was trying to make error message relating from the w3schools learning center but it returned nothing. please help me find the error.... here is the code i wrote... <?php// define variables and set to empty values$cnameErr = $dateErr = $itemErr = $rateErr = $qtyErr = "";$cname = $date = $rfn = $item = $rate = $qty = $less = $amt = "";if ($_SERVER["REQUEST_METHOD"] == "POST"){ if (empty($_POST["cname"])) {$cnameErr = "Customer Name is required";} else {$cname = test_input($_POST["cname"]);} if (empty($_POST["date"])) {$emailErr = "Date is required";} else {$date = test_input($_POST["date"]);} if (empty($_POST["rfn"])) {$rfn = "";} else {$rfn = test_input($_POST["rfn"]);} if (empty($_POST["item"])) {$itemErr = "Item name is required";} else {$item = test_input($_POST["item"]);} if (empty($_POST["rate"])) {$rateErr = "Please input Rate";} else {$rate = test_input($_POST["rate"]);} if (empty($_POST["qty"])) {$qtyErr = "Please input item quantity";} else {$qty = test_input($_POST["qty"]);} if (empty($_POST["less"])) {$less = "";} else {$less = test_input($_POST["less"]);} if (empty($_POST["amt"])) {$amt = "";} else {$amt = test_input($_POST["amt"]);}}function test_input($data){ $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data;}// error messageecho $dateErr; // and so on?>
  3. I created a php contact form for our Technology department in a school district. I would like to make a particular field required or optional based on the choice made in a dropdown menu.So, if the user chooses the Hardware or Software category, I want the barcode field to be required. If they choose Username/Password, I want the barcode field to be optional.Here is the part of the code that is validating fields: function died($error) { // your error code can go here echo "<b>We are very sorry, but there were error(s) found with the form you submitted.</b><br /> <br />"; echo $error."<br />"; echo "Please go back and fix these errors.<br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['location']) || !isset($_POST['email']) || !isset($_POST['machine']) || !isset($_POST['problem'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $location = $_POST['location']; // required $email_from = $_POST['email']; // required $machine = $_POST['machine']; // required $barcode = $_POST['barcode']; // not required $problem = $_POST['problem']; // required $issue = $_POST['issue']; $error_message = ""; if(($issue) == '') { $error_message .= 'Please select a category.<br />';} if(($issue) == "Hardware" || "Software" && ($barcode) == '') { $error_message .= 'The Service Tag/Barcode you entered does not appear to be valid.<br />'; } $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z0-9, .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$location)) { $error_message .= 'The Location you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$machine)) { $error_message .= 'The Machine you entered does not appear to be valid.<br />'; } if(strlen($problem) < 2) { $error_message .= 'The problem you entered does not appear to be valid.<br />'; } if(strlen($error_message) >= 1) { died($error_message); } The problem is that this always setting $error_message to 'The Service Tag/Barcode you entered does not appear to be valid.<br />'. So, when user selects Username/Password the error message is still preventing the script from sending the email.Any ideas?Lucas Land
×
×
  • Create New...