Jump to content


Photo

More than one button into one form


  • Please log in to reply
3 replies to this topic

#1 firedrop84

firedrop84
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 21 March 2006 - 07:44 AM

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.



#2 webwiese

webwiese
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 21 March 2006 - 07:58 AM

[!--quoteo(post=356884:date=Mar 21 2006, 08:44 AM:name=firedrop)--][div class=\'quotetop\']QUOTE(firedrop @ Mar 21 2006, 08:44 AM) View Post[/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


<?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

?>




#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 21 March 2006 - 08:21 AM

Give buttons the same name then check the value to get clicked button

<?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>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 firedrop84

firedrop84
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 21 March 2006 - 12:00 PM

thanx for the script. It is working on my page now.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users