Good day.Essentially, I am trying to have a custom action button on the add/update form. Is there a way to create a callback that gets fired only when I click the "save" button as distinct from "save and go back to list" button?
I am not aware of built-in way to do it, but you can do following (quick and dirty) thing in order to differ weather "Save" or "Save and go back to list" was clicked:
Following steps are used for flexgrid theme and ADD action. You should adjust the code by the theme you are using and also add same code for EDIT action.
First, add one hidden field into file:
/assets/grocery_crud/themes/flexgrid/views/add.php
<input type="hidden" name="my_button_name" id="my_button_name" value="save" />
just above comment line:
<!-- End of hidden inputs -->
Second, go to /assets/grocery_crud/themes/flexigrid/js/flexgrid-add.js
and add following line:
$('#my_button_name').val("save_and_close");
just below line:
save_and_close = true;
We will update this hidden field only if "Save and go back" was clicked, else we will keep default "Save" value.
Third, go to your controller, and read this field from POST array:
if (isset($_POST["my_button_name"]) && $_POST["my_button_name"] == 'save_and_close' )
{
// save and close clicked
}
else
{
// save clicked
}
That should be all. If you figure out "more proper" way to do it, let me know.