Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass data from form without a form field? (PHP)

I have a form for editing a users name and email. So when it updates the name and email, it needs the username to identify which row it should update.

So i wanted to know if there is any element which is passed with the form but without showing the value or being editable in the input tag.

So i get the username from one script. The edit user script gets the name and email from the database with the specified username. Then it passes that new name and email with the username to another script which updates it.

like image 858
Arjun Bajaj Avatar asked Apr 23 '11 14:04

Arjun Bajaj


2 Answers

I believe you are looking for

 <input type='hidden' name='username' value='theusername' />

hidden - can only be seen in the source of your HTML document
name - where it will be in the $_REQUEST/$_POST/$_GET ($_POST or $_GET depending on how you are submitting your form) variable on submit
value - the username you want this form to relate to

PRO TIP: Have a way to tell who is trying to update users so you don't have unauthorized people updating your user information. It would be very easy for someone to change the username in the form and try to update someone else.

like image 186
afuzzyllama Avatar answered Oct 02 '22 21:10

afuzzyllama


You can use input type hidden

<input type="hidden" name = "username" value="<?php echo $username ?>">
like image 25
jimy Avatar answered Oct 02 '22 21:10

jimy