todolistPhp / addTask.php
addTask.php
Raw
<?php
include("includes/config.php"); 

if(!isset($_POST['taskName']) ){
    header("location: index.php");
} else {
    $taskName = $_POST['taskName'];
    $deadLine =  strtotime($_POST['deadLine']);

    // create object 
    $task1 = new Tasks();

    if($task1->setTaskName($taskName)){ // check if the name is saved 
        if($task1->setTaskDeadline($deadLine)){ // check if the deadline is checked 
            if($task1->saveTodo()) { // save the task to json file
                header("location: index.php");      
            } else {
                header("location: index.php");        
            }
        } else {
            // error msg for the task deadline
            $_SESSION['errorDatemsg'] = "Ange en giltig deadline";
            header("location: index.php");
        } 
    } else {
        // error msg for the task name
        $_SESSION['errorNamemsg'] = "Ange minst 5 tecken";
        header("location: index.php");
    }
} 


?>