Take the 2-minute tour ×

I need to have a value in a text field auto filled with a pre-selected variable. Can the string be sent through a hyperlink and be filled in to a html form "text" area?

    <form method="POST" action='googler.php'>
    <label for="query">Query</label><br/>
    <input name="query" type="text" size="60" maxlength="60" value="" /><br /><br /> 

In other words can the "value" be filled with something else If I have used a link to get to this page?

share|improve this question
<textarea><?php echo $_GET['queryname'] ?></textarea>? –  Marc B Jul 17 '13 at 15:43
@MarcB — Danger! XSS! –  Quentin Jul 17 '13 at 15:44
The for attribute for a label references the id of the form control it is associated with. Your input doesn't have an id. –  Quentin Jul 17 '13 at 15:45

2 Answers 2

up vote 2 down vote accepted

Nothing in a URL will cause a browser to auto-populate a field.

Any part of a URL (although a query string parameter is traditional) can be used by server side code to set the value attribute value when the HTML is generated.

value="<?php echo htmlspecialchars($_GET['foo']); ?>"
share|improve this answer
So, can I create something like this from the other page that passes the value? echo (<a href = 'googler.php?query='.$suggestion[$ss_count].</a>'<br>'); –  the5thace Jul 17 '13 at 16:01
Yes. So long as you get your quotes in the right places. –  Quentin Jul 17 '13 at 16:03

Sure, you can put the value you want to fill in the URL, like: www.yourdomain.com?myval=test, and then just get that value with $_GET['myval']

share|improve this answer
Sounds like this might just be what I need. Could you elaborate on that please? –  the5thace Jul 17 '13 at 15:49
If I understand you right. I can create a hyperlink that holds a value and then GET the value in to value field? –  the5thace Jul 17 '13 at 15:51

Your Answer


