PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Bob   Quick DD   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: Quick DD
Generate form select inputs from dates or arrays
Author: By
Last change: didn't look good when pasted
Date: 12 years ago
Size: 2,954 bytes
 

Contents

Class file image Download
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>QuickDD Class Examples</title>
</head>
<body>
    <?php require("quickdd.php");?>
<h1>QuickDD Class Examples</h1>

    <p>Below you'll see the three functions in QuickDD demonstrated. To see the PHP code please open this file in your coding editor.</p>

    <h2>Date drop-down</h2>

    <p>The following drop-down displays date in format "DD-MM-YYYY". The pre-selected date is 21/12/2012. Start and end year are also set using the class variables.</p>
    <p>Select date: <?php
    QuickDD
::$start_year=2009;
   
QuickDD::$end_year=date("Y")+10;

   
// see how we pass the base name for the dropdowns, values, and markup array which will
    // set DOM ID, CSS class, and Javascript callback to every drop-down.
    // Of course all this is optional
   
echo QuickDD::date("final", "2012-12-21", "DD-MM-YYYY", array(" id='selectDay' class='some_class' onchange='doSomething(this.value);' "," id='selectMonth' class='some_class' onchange='doSomething(this.value);' ", " id='selectYear' class='some_class' onchange='doSomething(this.value);' "));
   
    if(!empty(
QuickDD::$errors)) print_r(QuickDD::$errors);
   
?></p>

    <h2>Drop-down with associative arrays</h2>

    <p>This example shows how to use the class methods with associative array. Let's for example have a list of students coming from databas. Each student has ID, name, and email. In the dropdown we want to display name, but sent ID by post (as most often you will use these forms to call some server-side code.</p>

    <p>Select student: <?php
   
// let's use static array here. Of course it can come from database or elsewhere
   
$students=array(
        array(
"id"=>1, "name"=>"John", "email"=>"john@dot.com"),
        array(
"id"=>2, "name"=>"Emma", "email"=>"emma@dot.com"),
        array(
"id"=>3, "name"=>"Dan", "email"=>"dan@dot.com")
    );

   
// note that unlike date() the other methods output only the option tags
    // so you need to output the select tag yourself thus being able to add any markup easily
   
?>
<select name="student_id">
    <option value="">- Please select -</option>
    <?php echo QuickDD::hash($students, "id", "name", 2);?>
</select></p>

    <h2>Drop-down with simple arrays</h2>

    <p>This will be a simple color selection. We will display some colors from PHP array and will want to see what customer selects. So both values and displays will be the same. There is no pre-selected color in this example.</p>

    <p>Select color: <?php
   
// here's the color array
   
$colors=array("black","white","blue","green","red","orange","yellow");
   
?>
<select name="color">
    <option value="">- Please select -</option>
    <?php echo QuickDD::arrays($colors, $colors);?>
</select></p>

    <script>
    function doSomething(id)
    {
        // nothing
    }
    </script>
</body>
</html>