If you are using CodeIgniter , there are more efficient ways to do this. (Another post for CodeIgniter indicates that this is a duplicate, so I thought I'd add a better solution for CI .)
In my case, I have a shopping cart form (for example). In this form, I can have buttons: checkout, update cart and clear.
the form:
Here are the form buttons on the cart form screen:
<input type="submit" value="Update"> <input type="submit" value="Clear"> <input type="submit" value="Checkout">
Controller:
The form action points to the controller with the method saved ( "cart/save/" ). Save simply determines which button was clicked, and forward to the appropriate basket function to handle submitting the form.
Cart / Save ()
public function save() { $submit_button = $this->input->post('submit_button'); if ($submit_button == 'Update') $this->update(); else if ($submit_button == 'Checkout') $this->checkout(); else if ($submit_button == 'Clear') $this->clear(); }
Inside the controller ( cart ) I just have the functions update() , clear() and checkout() , which the save() method calls. There is no need to redirect through CI () redirection or php header redirection, etc.
I hope this helps someone
source share