NMED 3850 A Advanced Online Design February 1, 2010 V. Mahadevan
Some More Fundamentals HTML user interfaces can consist of more than just text fields and buttons. Various user interface components are: Drop down menus. Radio buttons. Checkboxes. Text areas. You can encapsulate these components in your HTML forms (surround with tags) to make the input more intuitive and easier to understand.
Fundamentals (cont.) Drop down menu: Eins Zwei Drei Vier Funf
Fundamentals (cont.) Radio buttons: Zero One Checkboxes: Eins: Zwei:
Fundamentals (cont.) Text areas: The values of the various UI components can be passed to a PHP script using the POST method, just like the content of the text fields we’ve used earlier.
PHP $_POST Processing Remember the special array $_POST that captures the data from submitted HTML forms. <?php $numbers = $_POST['numbers']; $binary = $_POST['binary']; $numbers2 = $_POST['numbers2']; $textarea = $_POST['tarea']; print $numbers; print " "; print $binary; print " "; print count($numbers2);
PHP $_POST Processing (cont.) print " "; foreach ($numbers2 as $item) { print $item; print " "; } print $textarea; print " "; ?>
PHP $_POST Processing (cont.) You can also pass hidden form values to a PHP script from an HTML form: HTML: PHP: $hiddendata = $_POST['hiddendata'];
PHP $_GET Processing Sometimes you want to pass data to a PHP script without using a form. For this, the GET method can be used instead of POST. HTML: PHP test PHP: $data1 = $_GET['somedata'];
Adding Style With PHP Just like with HTML, when you generate HTML from within PHP you can attach a pre-existing CSS style sheet to it or use CSS styles in the HTML header. HTML header with embedded style: print " "; print "body { background-color: green;}"; print " ";
Adding Style With PHP (cont.) HTML header with an external stylesheet: print " "; The stylesheet itself will contain only one line: body { background-color: green;}
Form Validation With PHP Simple form validation can be done in PHP using by using “if” statements. Example: if ($_POST["last_name"]) == "") { // print an error message }
Lab Write PHP scripts that: Generate an HTML user interface comprising various elements such as checkboxes, radio buttons, and drop down menus. Perform form validation on the entered data. Insert the data into a database table. Retrieve and display the data from a database table. The final output must make use of a CSS style sheet.
References