• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
One Form, Two Buttons

I have a form with two submit buttons, but am having trouble trying to take a different action depending on the button pressed.

Here's a section of the form:

<p>Are you sure you want to delete this record?</p>

<div class='buttons'>
<span class='space'></span>

Here's the validation class run part:

if ($this->validation->run() == FALSE)
    // prepopulate form
    $this->validation->id = $id;
    if ($this->input->post("cancel"))
        echo "cancel!";

There is no "cancel!" output, so there's no cancel post variable..?
If I remove the if statement, it will echo "cancel!"..

The button that is clicked is added to the post global so your code is correct. But you should check the clicked button to perform the validation so your code would have to be something like
if(isset($_POST['delete']) && ! $this->validation->run())



Thanks xwero!, using the $_POST variable directly works.

I don't understand why I can't use the input->post() in this case but anyway it works now..

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.