Hi. What is the best check that the form has been submitted? Let’s have <input type="submit" name="submit" >

what I just did not meet:

1. The most popular option if (isset($_POST['submit'])

2. The same option if (isset($_POST['submit']) && !empty($_POST['submit']))

3.But I looked at the option the most: if ($_POST['photoList']=='submit') ; This option includes, by default, the first 2 checks. Why is it so massively not used?

C post seems to be less clear, but what about the GET form submission? After all, anyone can write in the address bar the desired parameter

  • and if $_POST['photoList'] does not exist? The error will give. - Smash

2 answers 2

The last option is not used, since if there was no submission, there will be a warning about the nonexistent array key.

IMHO, from simple the best option:

 function form_submitted($form_name=false){ if(!isset($_POST['submitted'])){ // был ли вообще сабмит return false; //неа, завершаем } if($form_name && $_POST['submitted']!=$form_name){ //если проверяется конкретная форма, была ли отправлена именно она? return false;//нет, завершаем } return true;//все, ок. } 

A more complicated option is to generate a unique hash for each form generation, so that it cannot be sent several times, for example, when updating

Put a link to this method

  • What is this technique called? It interested me very much. If you can link or please add your post. We write random hash on the first page of the session, and on the new page we check its existence? Grateful. - SverxnovA 2:22 pm
  • updated ... - knes pm
  1. Yes, this is the best option, use it
  2. It is not clear why the second condition, if submit is value = "(empty line, here is more http://php.net/manual/ru/function.empty.php) then your code will mark the form as unsent, except for that error, it is nothing does not give.
  3. That's right, anyone can just write in the address bar all the necessary data and it will be equivalent to sending the form. However, there is a trick, you can check the referrer from which the user came, to ensure that it was equal to the current page.
  • About the referrer, thank you ... - SverxnovA