Jump to content

Can I have two buttons in a form?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
ezcat

ezcat

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
In the following code, how can I tell if the VALUE="SaveComment" or the VALUE="CharacterCounter" button was pushed?


Echo '<FORM ACTION="addcomment.php" METHOD=POST>';

Echo 'Type your comment in the box below, then click on "Save Comment".<BR>';

Echo '<TEXTAREA NAME="Add_Comment" COLS=70 ROWS=4></TEXTAREA>';

Echo '<p><INPUT TYPE=SUBMIT VALUE="SaveComment"><INPUT TYPE=SUBMIT VALUE="CharacterCounter"></p>';

Echo '</FORM>';


When "addcomment.php" is called I would like to have code to either save the comment or count the characters in the comment, but need to know which button was pushed.

Thanks,
Jon

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
you need a name on your input tag, and then that name will have the value as value when sent back. Example:

<input type="submit" name="firstbutton" value="Press here for 1">
<input type="submit" name="secondbutton" value="Press here for 2">

pressing the first button would give the variable $_POST['firstbutton'] to contain the string "Press here for 1" in the recieving page's variables.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
ezcat

ezcat

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
thanks much. works great!

Jon