Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

angel angel
angel angel
6,620 Points

How to use sessions instead of passing data through <input> tags. in php? I need to add sessions I dont know how! HELP

""" <!DOCTYPE html> <html> <head> <title>Task List Manager</title> <link rel="stylesheet" type="text/css" href="main.css"> </head> <body> <header> <h1>Task List Manager</h1> </header> <main> <p><?php print_r($task_list); ?></p>

    <!-- part 1: the errors -->
    <?php if (count($errors) > 0) : ?>
    <h2>Errors:</h2>
    <ul>
        <?php foreach($errors as $error) : ?>
            <li><?php echo $error; ?></li>
        <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    <!-- part 2: the tasks -->
    <h2>Tasks:</h2>
    <?php if (count($task_list) == 0) : ?>
        <p>There are no tasks in the task list.</p>
    <?php else: ?>
        <ul>
        <?php foreach( $task_list as $id => $task ) : ?>
            <li><?php echo $id + 1 . '. ' . $task; ?></li>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>
    <br>

    <!-- part 3: the add form -->
    <h2>Add Task:</h2>
    <form action="." method="post" >
        <?php foreach( $task_list as $task ) : ?>
          <input type="hidden" name="tasklist[]" 
                 value="<?php echo $task; ?>">
        <?php endforeach; ?>
        <label>Task:</label>
        <input type="text" name="newtask" id="newtask"> <br>
        <label>&nbsp;</label>
        <input type="submit" name="action" value="Add Task">
    </form>
    <br>

    <!-- part 4: the modify/promote/delete form -->
    <?php if (count($task_list) > 0 && empty($task_to_modify)) : ?>
    <h2>Select Task:</h2>
    <form action="." method="post" >
        <?php foreach( $task_list as $task ) : ?>
          <input type="hidden" name="tasklist[]" 
                 value="<?php echo $task; ?>">
        <?php endforeach; ?>
        <label>Task:</label>
        <select name="taskid">
            <?php foreach( $task_list as $id => $task ) : ?>
                <option value="<?php echo $id; ?>">
                    <?php echo $task; ?>
                </option>
            <?php endforeach; ?>
        </select>
        <br>
        <label>&nbsp;</label>
        <input type="submit" name="action" value="Modify Task">
        <input type="submit" name="action" value="Promote Task">
        <input type="submit" name="action" value="Delete Task">

        <br>
        <label>&nbsp;</label>
        <input type="submit" name="action" value="Sort Tasks">
    </form>
    <?php endif; ?>

    <!-- part 5: the modify form -->
    <?php if (!empty($task_to_modify)) : ?>
    <h2>Task to Modify:</h2>
    <form action="." method="post" >
        <?php foreach( $task_list as $task ) : ?>
          <input type="hidden" name="tasklist[]" value="<?php echo $task; ?>">
        <?php endforeach; ?>
        <label>Task:</label>
        <input type="hidden" name="modifiedtaskid" value="<?php echo $task_index; ?>">
        <input type="text" name="modifiedtask" value="<?php echo $task_to_modify; ?>"><br>
        <label>&nbsp;</label>
        <input type="submit" name="action" value="Save Changes">
        <input type="submit" name="action" value="Cancel Changes">
    </form>
     <p>Session ID: <?php echo session_id(); ?>
    <?php endif; ?>

</main>

</body> </html> """