Verification: a143cc29221c9be0

Pass arguments from javascript to php

Form's data will be in $_POST or $_GET

Using the content of forms in PHP. Name of elements of a form are also PHP variables as soon as the PHP script is the action of the form.

Example, the complete form:

"mytext" is the name given to the text input object in the form above.
The PHP script retrieves the name as key in the $_POST array:

Actually, when a file is loaded by the action property of a form, all objects of the form are given as parameters to the script file, with the format:

?name=value&name2=value2 ...

There parameters are a part of the URL with a GET request, there are invisible with POST.

And these parameters become variables and values in a PHP script.
In this case:

?mytext="the entered text"

The value is the text you have typed.

The hidden type allows to send data not provided by users

And if you want to send to the script on the server some values that are not obtained through the form, how to process?
A simple solution is the use of hidden elements, as this one:

This kind of element is not visible in the form, and has the only purpose add a value to other values provided by the form.

If you want to change dynamically the value to pass to the script, you can assign the value of the hidden tag, example:

document.myform.extra.value = "some value";