Example #1
0
function show_form($errors = '')
{
    if ($errors) {
        $error_text .= '<p class="error">';
        $error_text .= implode('</p><p class="error">', $errors);
        $error_text .= '</p>';
    } else {
        $error_text = '';
    }
    echo $error_text;
    if ($_GET['id']) {
        $item = new Item(MT_TABLE);
        $row = $item->row($_GET['id']);
    }
    //print the html form
    ?>
                <div class="table">
        		<img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
            	<img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                <form method="POST" action="item.php">
                <table class="listing" cellpadding="0" cellspacing="0" id="tabella">
                <thead>
                    <tr>
                        <th class="first" width="177">Name</th>
                        <th class="last">Field</th>
                    </tr>
                </thead>
                <tbody>
                    <tr> 
                        <td class="first">Label</td> 
                        <td class="last"><input type="text" name="label" value="<?php 
    echo $row['label'];
    ?>
"></td>
                    </tr>
                    <tr>
                        <td class="first">Link (Leave blank for parent menu)</td> 
                        <td class="last"><input type="text" name="link" value="<?php 
    echo $row['link_url'];
    ?>
"></td>
                    </tr>
                </tbody>
                </table>
                <input type="hidden" name="_check" value="1"/>
                <input type="hidden" name="_id" value="<?php 
    echo $_GET['id'];
    ?>
"/>
                <input type="submit" value="Go">
                </form>
                
                <?php 
    if ($_GET['id']) {
        ?>
                    <p><a href="sub_item.php?parent_id=<?php 
        echo $_GET['id'];
        ?>
" class="button">Add child</a></p>
                              
                    <?php 
        if ($_GET['has_child']) {
            ?>
                        <?php 
            if ($array = $item->child($_GET['id'])) {
                ?>
                            <h1>This item has these childs:</h1>
                            <div id="child-list">
								<?php 
                foreach ($array as $k => $v) {
                    echo '<a href = "sub_item.php?id=' . $v['id'] . '">' . $v['label'] . '</a><br>' . "\n";
                }
                ?>
                            </div>
                            <?php 
            }
        }
    }
}