206 Test2

  1. html minimum
    • <!DOCTYPE html>
    • <html>
    • <head>
    •     <meta charset="UTF-8">
    •     <title></title>
    • </head>
    • <body>

    • </body>
    • </html>
  2. PDO connection
    • <?php
    • // open connection
    • $connection = "mysql:host=localhost;dbname=jhshoppingcart";
    • $user = "root";
    • $pwd = "";
    • $db = new PDO($connection, $user, $pwd);
    • ?>
  3. form dropdown list min
    • <form action="Purchase.html"
    •   id="itemForm" method="GET"
    •           onsubmit="return validate()">        <select name="itemSelect">            <option value="-1">
    • Choose an Item
    • </option>
    • ...other options...
    • </select>
    • </form>
  4. how to add dynamic options in select
    • <select name="itemSelect">
    • <option value="-1">
    •    Choose an Item
    • </option>
    • <?php
    • $query = $db->query("Select * from items");
    • while ($row = $query->fetch())   
    • {
    •   $value = $row['itemId'];
    •   $name = $row['itemName'];
    •   echo "<option value=" . $value .
    •      ">" . $name . "</option>";
    • }
    • ?>
    • </select>
  5. create a textbox to enter a quantity that will be validated
    • <form action="Purchase.html"
    •     id="itemForm"
    •     method="GET"
    •     onsubmit="return validate()">
    •         <label for="itemQty">
    •             Enter Quantity
    •        </label>
    •   <input type="text" name="itemQty">
    •   <input type="submit" value="Purchase"/>
    • </form>
  6. important parts of form tag
    • <form
    •   action="Purchase.html"
    •   id="itemForm"
    •   method="GET"
    •   onsubmit="return validate()"
    •   >
    • </form>
  7. what is the JS to validate that a textbox(itemQty) is between 0 and 100.
    • function validate()   
    • {
    •   var qty=itemForm.itemQty.value;
    •   if (qty.match(/[^0-9]/)
    •      ||qty<1
    •      ||qty>100)
    •   {            
    •     itemForm.itemQty.style.border="solid
    •      red";
    •    validQty='false';
    •   }
    •   else
    •   {
    •     itemForm.itemQty.style.border
    •       ="none";
    •     validQty='true';
    •   }
    •   if (validQty=='true')
    •       return true;
    •   else
    •      return false;
    • }
  8. How do you pass f_itemQty to another page?
    • 1st page
    • <form ...>
    • <input type="text" name="f_itemQty">
    • </form>

    • 2nd page
    • <?php
    • $itemQty=$_GET['f_itemQty'];
    • echo "<td>".$itemQty."</td>";
    • ?>
  9. how to retrieve data from a single row from a db select
    • $itemID=($_GET["itemSelect"]);
    • $query = $db->query("SELECT * FROM items where itemID=$itemID");
    • if($row = $query->fetch())       
    • {
    •   $itemName = $row['itemName'];
    •   $itemPrice = $row['itemPrice'];
    •   $itemDesc = $row['itemDesc'];
    •   $itemImg = $row['itemImg'];
    • }
  10. how to echo a row of table data
    • <table border="1">
    •   <tr>
    •   <?php// open connection
    •   echo "<td>".$itemName."</td>"
    •       . "<td><img src =".$itemImg
    •           ." height=60 width=60></td>"
    •       . "<td>".$itemDesc."</td>"
    •       . "<td>".$itemPrice."</td>"
    •       . "<td>".$qty."</td>";
    • </tr>
    • </table>
  11. How to add a submit button labelled Checkout.
    • <form action="checkout.php">
    •     <input type="submit" value="Checkout"/></form>
  12. validate the following
    <input type="text" name="f_firstName"/><br>
    • <form action="goodbye.php" method="GET"
    •    id="checkoutId"
    •    onsubmit="return validate()">
    • <script>
    • function validate()
    • {            // validate firstName           
    • var firstName =
    •   checkoutId.f_firstName.value;
    • if(firstName.search(/[^A-Za-z]/)==-1
    •   && firstName!="")           
    • {          
    •    checkoutId.f_firstName.style.border =
    •     "none";               
    •    validFirstName=true;
    • }
    • else
    • {          
    •   checkoutId.f_firstName.style.border=
    •      "solid red";                 
    •   validFirstName=false;           
    • }
    • if (validFirstName==true && ...)
    •       return true;
    • else           
    •      return false;
    • }       
    • </script>
  13. how to add radio buttons
    • <input type="radio" name= "f_shipAddress"
    •    value="same" checked/>
    • <label id="shipId1">Use mailing address</label>   <label id="shipId2">Use different address</label>
    • <input type="radio" name="f_shipAddress" value="different"/>
  14. how to create a checkbox
    <input type ="checkbox" value="onions" name="toppings[]"/>                <label>Onions</label><br/>
  15. GET requests are
    used to send parameters to server and identify the data to be retrieved(e.g. can be used configure of a database query)
  16. GET request parameters are
    encoded and are visible as part of the request URL.
  17. POST request parameters are use to
    send information to the server(usually to be stored on the server.)
  18. POST request parameters are
    encoded inside the request and are not a visible part of the URL.
  19. $_GET and $_POST are __________ arrays consisting of
    associative arrays consisting of key/value pairs.
  20. $_GET["phone"] will retrieve the value sent from a client...
    form with an input element named "phone"
  21. name 3 methods to access a database
    • mysql
    • mysqli
    • PDO
  22. PDO is
    new, most flexible, object oriented method
  23. php is used to ...
    build web pages that contain dynamic content.
  24. php consists of HTML tags that...
    enclose static content and php<?php...?> tags that enclose dynamic content.
  25. Dynamic content is created using...
    echo or print statements.
  26. client side validation
    • ensures that data is valid
    • prevents bad data from being sent to the server
    • reduces workload on server
  27. HTML5 validation
    • detects missing data for required fields
    • checks simple text patterns for text input format
    • provides basic user notifications when errors occur
    • simple to code, but limited usefulness.
  28. JavaScript validation
    • detect many types of input error
    • can provide custom user notifications when errors occur
    • harder to code than HTML5 but more customizable
    • validation of text input formats can be done using pattern matching with regular expressions
  29. submitting form data
    • data sent to server according to form's action and method attributes values
    • data can be prevented from being sent by using onsubmit handler to validate form data
    • form data accessed in JS using formId.elementName.value
    • If onsubmit handler returns true, data is sent to server.
    • If onsubmit handler returns false, data is not sent to server.
  30. receiving form data on server
    • done using $_GET and $_POST arrays
    • $_GET arrays receive information send from client forms that make GET requests(with method="GET")
  31. HTML 5 Validation
    • required>
    • <input type ="email" or url, number, tel, date
    • <input type="email" name="email" required placeholder="Enter a valid email address">

    • password
    • color
    • date
    • datetime
    • datetime-local
    • month
    • search
    • tel
    • time
    • week
  32. HTML5 lastName validation
    • <label class="formlabel"> Last Name </label>           
    • <input type="text" value="Last"
    •     name="name[]"
    •     pattern="[A-Z][a-z]*"
    •     required="required"
    •     title="Upper case followed by lower case
    •                  e.g. Jones"           
    • />
  33. How to store input elements in an array
    • <input type ="checkbox" value="pepperoni"
    •      name="toppings[]"/>
    • <label>Pepperoni</label><br/>
    • <input type ="checkbox" value="mushroom"
    •      name="toppings[]"/>
    • <label>Mushrooms</label><br/>
  34. validate quantity for digits onkeypress
    • <input type="text" name ="qty" value = "1"
    • onkeypress="return numVal(event)">

    • function numVal(event)   
    • {
    •   var charCode = (event.which) ?
    •         event.which : event.keyCode;
    •   if (charCode==8||charCode==13 ||
    •      (charCode>47 && charCode<58))
    •             return true;
    •   else
    •             return false;
    • }
  35. onload, onclick, onchange, onkeypress
Author
slc53
ID
326062
Card Set
206 Test2
Description
206 Test2
Updated