Using Default Checkbox Values : Form Checkbox « Form « PHP

Using Default Checkbox Values

    <title>Using Default Checkbox Values</title>
$food = $_GET[food];
$self = htmlentities($_SERVER['PHP_SELF']);
if (!empty($food)) {
    echo "The foods selected are:<br />";
    foreach($food as $foodstuf)
        echo "<strong>".htmlentities($foodstuf)."</strong><br />";
    echo ("<form action=\"$self\" ");
    echo ('method="get">
        <label>Italian <input type="checkbox" name="food[]" value="Italian" />
        <label>Mexican <input type="checkbox" name="food[]" value="Mexican" />
        <label>Chinese <input type="checkbox" name="food[]" value="Chinese"
        checked="checked" /></label>
    <input type="submit" value="Go!" >');

Related examples in the same category

1.Responding to Checkboxes
2.A form with checkboxes using the same name to store multiple values
3.Checking input from a checkbox or a multiple select
4.Validating a single checkbox