0

I know in PHP you have $_GET, $_POST, and $_REQUEST to access form input through their names in the html tags. Is it possible to do the same for their ids? For example:

<form>
First name: <input type="text" id="firstname"><br>
Last name: <input type="text" id="lastname">
</form> 

In PHP:

$f_name = $_GET['firstname'];
torrential coding
  • 1,755
  • 2
  • 24
  • 34
Leon Helmsley
  • 575
  • 2
  • 6
  • 17

2 Answers2

2

When submitting a form, only the input fields with a name attribute are submitted. Just add a name attribute same as id, or do some JavaScript hack to populate name attributes on form submit.

Web_Designer
  • 72,308
  • 93
  • 206
  • 262
artahian
  • 2,093
  • 14
  • 17
0

No you cannot do this when submitting the form normally. You could however, use client-side JavaScript to construct the submission to the PHP script.

But this assumes you can modify the client-side page. If you can do that, you can also just add the correct names to the form fields.

<form>
First name: <input type="text" name="firstname" id="firstname"><br>
Last name: <input type="text" name="lastname" id="lastname">
</form> 
gzm0
  • 14,752
  • 1
  • 36
  • 64