<form method=post> <input type="hidden" name=name value="<?= $_POST['name'] ?>"> <input type="submit"> </form> 

I do not understand what the value attribute will pass

  • The value will contain the contents of the $_POST['name'] cell, if it is not empty and exists. - Opalosolo
  • Well, I clicked on submit and what happens next? What content have you written about ?? - hil400k

2 answers 2

because the hidden field, in this case it will always be empty if it is not filled on the browser side with some script.

I'll try to tell you how it works ...

Judging by the absence on the action form, the data will be sent to the same page. Therefore, we obtain the following algorithm:

  1. Open the page with the GET method (well, that is, you entered the url of the page into the address bar) Because GET request, not POST, no data will be in the $_POST superglobal array. And since you are trying to get missing data, you will probably get a warning about this from PHP. In general, when you try to display the contents of a non-existent variable, you get an empty string.
  2. Since $_POST['name'] is empty for us, the value of the element will be empty.
  3. Suppose the field is not hidden, but text, or we have a JS code that fills it with data
  4. After clicking on the submit button, these forms are already sent by the POST method (since the form method="POST" ), and on the server side, the $_POST array will no longer be empty, but will contain data from the form, i.e. $_POST['name'] will be equal to what was entered in the input.
  5. If we again show this form, then in this hidden field we will get what we had in $_POST['name'] , i.e. what was entered before submitting this form.
  • Gee, thanks for the answer - hil400k
  • @ hil400k, if the answer is exhaustive, tick it below the like buttons - vanchester
  • @vanchester, "if the answer is exhaustive, check it out ..." is a favorite phrase of the local karmadrocherov. Do not be like. - Indifferent
  • @ Indifferent, ok :) - vanchester
  • @ Indifferent, Isn’t that what the whole overflow institute is all about? In the plan, the collection of a large number of questions and the correct answers to them - i.e. it is necessary to mark an exhaustive answer as an exhaustive simply so that people know that the problem of the issue is solved? - Morlok

In fact, you are not transmitting anything (judging by the code that you provided). This is a meaningless form which conveys the value of what is contained in the $_POST['name'] array, that is, the same thing that was passed earlier.