CodeIgniter Forums
Single html Form With Multiple Submit Buttons - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Single html Form With Multiple Submit Buttons (/showthread.php?tid=36676)

Pages: 1 2


Single html Form With Multiple Submit Buttons - El Forum - 12-10-2010

[eluser]mo2men[/eluser]
hey

i wont two Submit Buttons in one page

example
i have textarea and i want preview Before submit it in database


1 submit and go to create.php
2 preview and go to preview.php


how i can do this in ci
like in Forum 'preview post' 'submit post'




Single html Form With Multiple Submit Buttons - El Forum - 12-10-2010

[eluser]cahva[/eluser]
Process the form in same controller, just make actions based on what submit button was clicked:

Code:
if ($this->input->post('preview'))
{

    // Show preview stuff

}

if ($this->input->post('create'))
{

    // Create stuff

}



Single html Form With Multiple Submit Buttons - El Forum - 12-11-2010

[eluser]mo2men[/eluser]
hi thanks

but i want action go to Other Controller or Other function
no same Controller
new Controller or new function

can i do that ?????????????


Single html Form With Multiple Submit Buttons - El Forum - 12-11-2010

[eluser]Atharva[/eluser]
I guess you need to use JS then. This will help you.


Single html Form With Multiple Submit Buttons - El Forum - 12-11-2010

[eluser]Twisted1919[/eluser]
[quote author="mo2men" date="1292081801"]
but i want action go to Other Controller or Other function
no same Controller
new Controller or new function
[/quote]
WHY ?


Single html Form With Multiple Submit Buttons - El Forum - 12-11-2010

[eluser]WanWizard[/eluser]
Without javascript, you can't. One form can only have one action.


Single html Form With Multiple Submit Buttons - El Forum - 12-12-2010

[eluser]umefarooq[/eluser]
you can't use multiple buttons to submit form only one button can work at one time but you can have multiple submit button on one page for one form with same name but different value for example

Code:
<form action="welcome/action">
<input type="submit" name="actionbtn" value="create" />
<input type="submit" name="actionbtn" value="preview" />
  </form>

now in your action get the button value if you are using CI

$action = $this->input->get_post("actionbtn");
switch($action){
case 'create':
    $this->create();
break;
case 'preview':
  $this->preview();
break;

call create or preview function of controller
}



Single html Form With Multiple Submit Buttons - El Forum - 12-12-2010

[eluser]umefarooq[/eluser]
you can't use multiple buttons to submit form only one button can work at one time but you can have multiple submit button on one page for one form with same name but different value for example

Code:
<form action="welcome/action">
<input type="submit" name="actionbtn" value="create" />
<input type="submit" name="actionbtn" value="preview" />
  </form>

now in your action get the button value if you are using CI

$action = $this->input->get_post("actionbtn");
switch($action){
case 'create':
    $this->create();
break;
case 'preview':
  $this->preview();
break;

call create or preview function of controller
}



Single html Form With Multiple Submit Buttons - El Forum - 08-04-2012

[eluser]Unknown[/eluser]
I have taken it from http://wintekweb.blogspot.com/2012/05/php-scripts-home.html
Try It


Single html Form With Multiple Submit Buttons - El Forum - 08-08-2014

[eluser]Bill Hernandez[/eluser]
Code:
<!-- block [8400], or [8600] both work correctly, [8500] does not. -->

<form method='post' action="">
    <input type="submit" name="action" value="create" />
    <input type="submit" name="action" value="preview" />
</form>

<?php
// +---------+---------+---------+---------+---------+---------+
// [8400] this block works correctly
// +---------+---------+---------+---------+---------+---------+
$action = $this->input->post("action");
switch($action)
{
    case 'create':
        // $this->create();
        echo '<br>[8401] create';
        break;
    case 'preview':
        // $this->preview();
        echo '<br>[8402] preview';
        break;
}

// +---------+---------+---------+---------+---------+---------+
// [8500] these two lines do nothing
// +---------+---------+---------+---------+---------+---------+
echo '<br>[8501] do nothing ' . $this->input->post('preview');
echo '<br>[8502] do nothing ' . $this->input->post('create');

// +---------+---------+---------+---------+---------+---------+
// [8600] these two blocks work correctly
// +---------+---------+---------+---------+---------+---------+
if ($this->input->post('action') == 'create')
{
    // $this->create();
    echo '<br>[8601] create';
}

if ($this->input->post('action') == 'preview')
{
    // $this->preview();
    echo '<br>[8602] preview';
}

?&gt;