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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding text field value to a url

Status
Not open for further replies.

bigbird3156

Programmer
Feb 20, 2001
183
AU
Hi,

if I have a text field on a page and I want to add the content of that field into a url once it has been submitted how do I call it?

for the sake of this example, I have a text field called "Tfield" and I want the URL after submitting the form to look like...

abc.php?Tfield=this+is+the+content+of+Tfield

The action part if the form would then look like
Code:
action="abc.php?Tfield=<?php echo urlencode (?????); ?>"

The Bird from Down Under- Bigbird 3156 [upsidedown]
 
Hi

That is the default behavior in case of GET method. While you are asking this, I suppose your [tt]form[/tt] is submitted with POST method. And while you are asking this, I suppose you can not simply change the method to GET because other fields.

If my above theory is correct and you want to have a [tt]form[/tt] submitted with POST method excepting one field which has to appear in the URL, then the solution would be JavaScript :
JavaScript:
<form action="abc.php" method="post" onsubmit="this.action+='?Tfield='+escape(this.Tfield.value)">
<input type="text" name="Tfield">
</form>
Or I misunderstood you...

Feherke.
 
There are 2 reasons I was going post instead of get...

first is I assumed through what I have done that get only allows you to sent 1 variable and although I have not said as much above I want to send 2 variables....

the second reason is that I need to use URLencode or another similar function and I could not work out how this could happen with Get but I thought I could do it with post, but looking at your example above maybe I was wrong there as well...

Using the Get function I have the following 2 pages...

Code:
<form id="form1" name="form1" method="get" action="abc.php">
  <p>
    <label>
      <input name="val1 " type="text" id="val1" value="test" />
    </label>
  </p>
  <p>
    <label>
      <select name="val2" id="val2">
        <?php
do {  
?>
        <option value="<?php echo $row_Recordset1['category']?>"><?php echo $row_Recordset1['category']?></option>
        <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
      </select>
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>
Code:
<body>
<?php echo $_GET["val1"]; ?><p>

<?php echo $_GET["val2"]; ?>
</body>

The only value that displays on the display page however is val2, I have no sign of val1 at all...

and I still have no idea how to use URLencode...

anyway thats about it...

The Bird from Down Under- Bigbird 3156 [upsidedown]
 
And here is the culprit....
Code:
<input name="val[COLOR=red]1 "[/color] type="text" id="val1" value="test" />

so don't worry I have solved it myself!!

The Bird from Down Under- Bigbird 3156 [upsidedown]
 
you can send as many variables as you want using GET (there are certain limitations on total string size, some browsers limit to 1500 characters).

you do not need to use urlencode if the variables are being submitted via a form using the GET method. you just specify the encoding type in the form tag. the browser takes care of the rest.

to use urlencode you simply do this

$url = ' //etc
[/code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top