NEP -PHP PROGRAMMING

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14

PART B

. . .

 
   
 9.Write a PHP script that receives string as a form input.

    

<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=""><br>

E-mail: <input type="text" name="email" value=""><br>

Website: <input type="text" name="website" value="">
<br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea><br>

 <br><br>
  <input type="submit" name="submit" value="Submit"> 
</form>


< ?php

$nameErr = $emailErr  = $websiteErr = "";
$name = $email  = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["name"])) {
    $nameErr = "Name is required";
  } else {
    $name = test_input($_POST["name"]);
   
    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"]);
    
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format";
    }
  }
    
  if (empty($_POST["website"])) {
    $website = "";
    
  } else {
    $website = test_input($_POST["website"]);
  
    }
  }

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

   
}

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





< ?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;
?>

</code>
</pre>

</div> 






 <div class="row">






 <div class="">

<!-- <aside class="">
    <h3>Navigation</h3>
    <div class="aside-nav">
       <ul>
          <li><a>Home</a></li>
          <li>
             <a>Product</a>
             <ul>
                <li><a>Product 1</a></li>
                <li><a>Product 2</a></li>
                <li>
                   <a>Product 3</a>
                   <ul>
                      <li><a>Product 3-1</a></li>
                      <li><a>Product 3-2</a></li>
                      <li><a>Product 3-3</a></li>
                   </ul>
                </li>
             </ul>
          </li>
          <li>
             <a>Company</a>
             <ul>
                <li><a>About</a></li>
                <li><a>Location</a></li>
             </ul>
          </li>
          <li><a>Contact</a></li>
       </ul>
    </div>
 </aside>-->
</div>


 <div class="col-lg-12" id="main">
   <div class="boxcolorc1">
   <p><b> </b>   </p>
</div>





</div>
<div id="footer-bg">
 <div id="footer-content" class="container">

 </div>
</div>

</div>

</div>

    </div>
<!-- end #footer -->
</body>
</html>
<script>
function w3_open() {
  document.getElementById("mySidebar").style.display = "block";
}
function w3_close() {
  document.getElementById("mySidebar").style.display = "none";
}
pageid="link9";
setActive(pageid);

function setActive(elmt){
var d = document.getElementById(elmt);
d.className += " w3-green";
}
</script>