-1
I am developing a task manager. Obviously I need a task add function.
function loadInputForm () {
global $title, $status,$description, $date;
if($_POST){
$title = filter_input(INPUT_POST, "titulo");
$status = filter_input(INPUT_POST, "status");
$description = filter_input(INPUT_POST, "descricao");
$date = filter_input(INPUT_POST, "data");
}
if($title){
$taskInput = "$title%$status%$description%$date\n";
addTasks($taskInput);
}
}
With the above code I receive the form information and save it in a string with the tab "%".
function addTasks ($taskInput) {
$fileOpen = fopen(PATH, 'a');
fwrite($fileOpen, $taskInput);
fclose($fileOpen);
}
Here I open a file with a native PHP function and write the string with the form data in that file with the fwrite() function. For the interface I simply break the text of this file with strings handling functions and display them to the user.
The problem is that when the user finishes filling the form and presses the send data button, the page is updated but the content is not added. It only appears in the interface after refreshing the page again. Hence another problem arises, after this second update of the page, the form is resubmitted, and the data previously typed by the user is again written in the file, causing a repetition of content.