Welcome Guest, Not a member yet? Register   Sign In
Single html Form With Multiple Submit Buttons
#1

[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'

#2

[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

}
#3

[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 ?????????????
#4

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

[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 ?
#6

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

[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
}
#8

[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
}
#9

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

[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;




Theme © iAndrew 2016 - Forum software by © MyBB