![]() |
Two Submit Buttons in Forms - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Two Submit Buttons in Forms (/showthread.php?tid=13080) |
Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]Bl4cKWid0w[/eluser] I have a "form" that requires the user to accept or decline a request. I tried using $_POST with an if statement, but all that did was cause the CI scripts to think that the name of the button was a variable. How would I do something like this? Example: <form action='$_SERVER['PHP_SELF']' method='POST'> <input type='submit' name='accept' value='Accept'> <input type='submit' name='decline' value='Decline'> </form> Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]Renard Urbain[/eluser] This is "only" possible in asp.net. Otherwise you have to do or: <form action="<action>" method="post"> <input type="submit" name="accept" value="Accept" /> </form> <form action="<action>" method="post"> <input type="submit" name="decline" value="Decline" /> </form> OR: <form action="$_SERVER[‘PHP_SELF’]" method="POST"> <input type="submit" name="accept" value="Accept"> <input type="submit" name="decline" value="Decline"> <input type="hidden" name="action" id="action" value="" /> </form> Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]Bl4cKWid0w[/eluser] [quote author="Renard Urbain" date="1226371437"]This is "only" possible in asp.net. [/quote] Not true. I've done it with regular PHP before I started using code igniter. Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]Renard Urbain[/eluser] Interesting, that is something I haven't tried so far. So what do you want to do exactly ? If you press accept $_POST = array('accept' => 'Accept'); otherwise $_POST = array('decline' => 'Decline'); Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]Bl4cKWid0w[/eluser] Something like this: if(!($_POST['accept']) || ($_POST['decline'])){ load form } else { perform action } Basically if neither of the buttons are pressed, the form is submitted. If one of them is pressed, a function is performed that will determine which one is pressed and will go from there. Edit: Sorry, if neither of the buttons are pressed, the form is displayed, not submitted. Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]Renard Urbain[/eluser] Ah! Not exactly in the best practices but I would do something similar to : if(!isset($_POST['accept']) or !isset($_POST['decline'])) $this->load->view('the_form'); else // do the stuff Note that to access the $_POST you need to set $config['enable_query_strings'] = TRUE; in /system/application/config/config.php otherwise you can access your post arrray via $this->input->post(<name>); Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]BaRzO[/eluser] in ci you can do this in controller Code: <?php view file Code: <?=form_open("get_values")?> Two Submit Buttons in Forms - El Forum - 11-10-2008 [eluser]Bl4cKWid0w[/eluser] Thanks, Barzo. That worked. Two Submit Buttons in Forms - El Forum - 11-11-2008 [eluser]Nick Husher[/eluser] Note that you could just name the buttons the same thing with different values: Code: //HTML Code: //PHP Two Submit Buttons in Forms - El Forum - 11-11-2008 [eluser]dimethroxy[/eluser] [quote author="Nick Husher" date="1226456839"]Note that you could just name the buttons the same thing with different values: Code: //HTML Code: //PHP This is actually the best method. |