Project Challenge: Create and List Tasks

Let's implement the features we recently learned in the previous project.

Problem statement

This challenge builds on top of the previous one, so we will continue to work on the project that we have already created.

Next steps:

  • Split the existing /tasks page in a /list-tasks page and a /create-task page. The form goes to the /create-task page, and the list of previously created tasks goes to /list-tasks. Both pages need to be accessible only when you are logged in.
  • On the /create-task page, when the request method is POST, start by normalizing the submitted data and validating it. For now, the only validation rule is that the task can’t be an empty string. When form validation fails, show an error next to the task form field.
  • Instead of storing the tasks in the session, we are going to store the tasks in a JSON file called data/tasks.json. A new task should be stored as an array: ['username' => $_SESSION['authenticated_user'], 'task' => $normalizedData['task']]. After saving, redirect the user to /list-tasks.
  • Now that tasks are stored in tasks.json, the /list-tasks page should load the tasks from this file and show them. Make sure that you only show the tasks of the currently logged in user! This is one way to accomplish that:

Get hands-on with 1400+ tech skills courses.