using one text box for different variables (php)

Status
Not open for further replies.

zach014

Baseband Member
Messages
29
i've seen websites use one text box to submit different things depending on which button they click.
for example, i have a buy button and a sell button next to each other, and one text box to the right of them. i want it so that if they click buy, it will read the contents of the text box as if it were a different text box than if someone clicked sell.
thanks in advance,
~zach
 
Hmm, what'cha mean? Like this?

http://www.vormund.net/eg/buysell.php

Click the button, and it'll be echoed out along with the text box. So then you could do a simple
PHP:
if ( $_POST['butonName'] ) {
  // do this
} else {
  // do this
}
The code behind buysell.php is very simple:

PHP:
<?php 
foreach( $_POST as $var => $val )
  echo $var.":".$val."<br>";
?>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
  <input type="text" name="stuff"><br>
  <input type="submit" name="buy" value="Buy">
  <input type="submit" name="sell" value="Sell">
</form>
I guess the bottom line is by putting a name on the submit tag, it'll show up as a variable, too.
 
Status
Not open for further replies.
Back
Top Bottom