B
B
BuBux2020-04-13 18:44:39
PHP
BuBux, 2020-04-13 18:44:39

How to organize logic?

On all pages of the site there is a button "Add task", which leads to the form for adding a task. There is a page with its own tasks ("My tasks"). There are two selects on the task adding form, which should not be displayed if the user has navigated from the "My Tasks" page.
Entered additional variable $display_users = 1, and then parse the url from which the user came:

$url = $_SERVER['HTTP_REFERER'];
$str = explode("//", $url);
$str_ = explode("/", $str[1]);

if ($str_[2] == 'my') {
  $display_users = 0;
}

Then in the html document I wrap the select data in a condition:
<?php if ($display_users) : ?>
    // показываю
    ....
<?php else: ?>
    // создаю скрытое поле, необходимое мне в дальнейшем
  <input type="hidden" name="display_users">
<?php endif; ?>

Next in the controller, I check the form submission:
if (isset($_POST['submit'])) {
        ....
}

The bottom line is that if I go to add a task from the "My Tasks" page for the first time, everything works as it should. But then the form has a validation check. And if the user entered something incorrectly, then the selects reappear. How can this situation be resolved?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question