Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Value= Please Help 1

Status
Not open for further replies.

chuckbridges

Programmer
Apr 15, 2005
19
US
I have a form (like who doesnt) And way Id like to
place some of my PHP variables like $user etc... into
the form as it is modifying a selected user...

How can I make the value= in an html form be equal to the
variable ?


Thanks

Chuck
 
Where are you getting the variable from? This is a simple html question. Being, whatever is put into the value attribute of the input field will appear in it as the prefilled value when the form loads. So, for instance:
Code:
$user = "chuckbridges";
echo '<input type="text" name="username" value="' . $user . '" />';
will print out a text box filled with chuckbridges. Now, only thing you have to determine is where does the value for $user come from.
 
Some times, you do not want to display the variables to the user. This is why you have the <input type="hidden" />

eg. You can do as such:

Code:
<form action="?foo=bar">
 <input type="hidden" name="userid" value="<?=$userid?>" />
 <input type="text" name="username" value="<?=$username?>" />
 <textarea name="information" cols="20" rows="15">
  <?=$information?>
 </textarea>
 <input type="submit" value="Edit" name="action" />
</form>

Just make sure that the name equals the variable-name, as then when submitted, that variable will be filled with the value of the input which has that name.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top