function show_form($errors = '')
{
    // If the form is submitted, get defaults from submitted parameters
    if (array_key_exists('_submit_check', $_POST)) {
        $defaults = $_POST;
        var_dump($defaults);
    } else {
        // Otherwise, set our own defaults: price is $5
        $defaults = array('price' => '5.00', 'dish_name' => '', 'is_spicy' => 'no');
    }
    // If errors were passed in, put them in $error_text (with HTML markup)
    if (is_array($errors)) {
        $error_text = '<tr><td>You need to correct the following errors:';
        $error_text .= '</td><td><ul><li>';
        $error_text .= implode('</li><li>', $errors);
        $error_text .= '</li></ul></td></tr>';
    } else {
        // No errors? Then $error_text is blank
        $error_text = '';
    }
    // Jump out of PHP mode to make displaying all the HTML tags easier
    ?>
<form method="POST" action="<?php 
    print $_SERVER['PHP_SELF'];
    ?>
">
<table>
<?php 
    print $error_text;
    ?>

<tr><td>Dish Name:</td>
<td><?php 
    input_text('dish_name', $defaults);
    ?>
</td></tr>

<tr><td>Price:</td>
<td><?php 
    input_text('price', $defaults);
    ?>
</td></tr>

<tr><td>Spicy:</td>
<td><?php 
    input_radiocheck('checkbox', 'is_spicy', $defaults, 'yes');
    ?>
 Yes</td></tr>

<tr><td colspan="2" align="center"><?php 
    input_submit('save', 'Order');
    ?>
</td></tr>

</table>
<input type="hidden" name="_submit_check" value="1"/>
</form>
<?php 
}
Example #2
0
function show_form($errors = '')
{
    // If the form is submitted, get defaults from submitted parameters
    if (array_key_exists('_submit_check', $_POST)) {
        $defaults = $_POST;
    } else {
        // Otherwise, set our own defaults: medium size and yes to delivery
        $defaults = array('name' => '', 'sweet' => 'puff', 'main_dish' => array('cuke'), 'comments' => '', 'delivery' => 'yes', 'size' => 'medium');
    }
    // If errors were passed in, put them in $error_text (with HTML markup)
    if ($errors) {
        $error_text = '<tr><td>You need to correct the following errors:';
        $error_text .= '</td><td><ul><li>';
        $error_text .= implode('</li><li>', $errors);
        $error_text .= '</li></ul></td></tr>';
    } else {
        // No errors? Then $error_text is blank
        $error_text = '';
    }
    // Jump out of PHP mode to make displaying all the HTML tags easier
    ?>
<form method="POST" action="<?php 
    print $_SERVER['SCRIPT_NAME'];
    ?>
">
<table>
<?php 
    print $error_text;
    ?>

<tr><td>Your Name:</td>
<td><?php 
    input_text('name', $defaults);
    ?>
</td></tr>

<tr><td>Size:</td>
<td><?php 
    input_radiocheck('radio', 'size', $defaults, 'small');
    ?>
 Small <br/>
<?php 
    input_radiocheck('radio', 'size', $defaults, 'medium');
    ?>
 Medium <br/>
<?php 
    input_radiocheck('radio', 'size', $defaults, 'large');
    ?>
 Large
</td></tr>

<tr><td>Pick one sweet item:</td>
<td><?php 
    input_select('sweet', $defaults, $GLOBALS['sweets']);
    ?>
</td></tr>

<tr><td>Pick two main dishes:</td>
<td>
<?php 
    input_select('main_dish', $defaults, $GLOBALS['main_dishes'], true);
    ?>
</td></tr>

<tr><td>Do you want your order delivered?</td>
<td><?php 
    input_radiocheck('checkbox', 'delivery', $defaults, 'yes');
    ?>
 Yes
</td></tr>

<tr><td>Enter any special instructions.<br/>
If you want your order delivered, put your address here:</td>
<td><?php 
    input_textarea('comments', $defaults);
    ?>
</td></tr>

<tr><td colspan="2" align="center"><?php 
    input_submit('save', 'Order');
    ?>
</td></tr>

</table>
<input type="hidden" name="_submit_check" value="1"/>
</form>
<?php 
}