I have a form where I can add a new category item.
<form method="POST" action="backend/categories/form">
<input type="text" name="title" value="" />
<button type="submit">Save</button>
<button type="submit">Save and add new</button>
</form>
What I want to do, is that if i click on Save
button, it will process a function in controller and redirect me automatically into the previous page (list of categories page), but whenever I click on Save and add new
, it should process the function but reload the same page without redirecting to the page which is defined in controller's function.
Controller:
function form($id){
// Process the form
// ...
// Redirect to the category list page
redirect($this->config->item('backend_folder').'/categories');
}
Any tips to achieve it without using the Javascript ?
Use this HTML:
<form method="POST" action="backend/categories/form">
<input type="text" name="title" value="" />
<button type="submit" name="submitForm" value="formSave">SAVE</button>
<button type="submit" name="submitForm" value="formSaveNew">SAVE AND ADD NEW</button>
</form>
Then check the POST data like this:
$formSubmit = $this->input->post('submitForm');
if( $formSubmit == 'formSaveNew' )
redirect($this->config->item('backend_folder').'/categories/form');
else
redirect($this->config->item('backend_folder').'/categories');
Disclaimer: I didn't try that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With