Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

firedrop84

More than one button into one form

Recommended Posts

I have another question. when I got for example in a form a submit button I usually use the action in the form and thats in the HTML to allow it to go for the page that I would like.

I am wondering what if I have two buttons that they do two different actions. How I can handle this.

Share this post


Link to post
Share on other sites
[!--quoteo(post=356884:date=Mar 21 2006, 08:44 AM:name=firedrop)--][div class=\'quotetop\']QUOTE(firedrop @ Mar 21 2006, 08:44 AM) [snapback]356884[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I have another question. when I got for example in a form a submit button I usually use the action in the form and thats in the HTML to allow it to go for the page that I would like.

I am wondering what if I have two buttons that they do two different actions. How I can handle this.
[/quote]


Hi,

don't use any action or use action = "<?echo $PHP_SELF?>" to call the same script. Then use an if ... elseif ... else - construct like

[code]

<?php

# Submit - Button #1
if (isset($_POST[submit_button_1]) {

   # action for submit - button #1

} // if

# Submit -  Button #2
elseif (isset($_POST[submit_button_2]) {

   # action for submit - button #2

} // if

# Standard - form
else {

   ?>

   <form method = "POST">
  
        .......

   </form>

   <?

} // else

?>

[/code]

Share this post


Link to post
Share on other sites
Give buttons the same name then check the value to get clicked button

[code]<?php

if (isset($_POST['submit'])) {

    switch ($_POST['submit']) {
            case 'A':
                  echo 'Button A was pressed<br>';
                  break;
            case 'B':
                  echo 'Button B was pressed<br>';
                  break;
    }

}
?>
<FORM METHOD='POST'>
<INPUT TYPE='SUBMIT'  name='submit' value='A'>
<INPUT TYPE='SUBMIT'  name='submit' value='B'>
</FORM>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.