I have a page (let’s call it edit page) with two forms – the first one for updating information in one table in the database and it has a submit button “Save”, and the other is for perstitng information in another table and it has its own button “Add” and a link – “Delete” to delete the existing rows. Whatever of the three Save, Add or Delete you press you should stay at the same page. Could you please advice me which will be the best way to make things:
-
When you press delete I’m routing to another url which calls deleteController in which body it redirects back to the previous page (edit page)
I couldn’t come up with anything better because Delete is a link. Feel free to give your suggestions and please tell whether my way is very stupid or it’s acceptable.
-
How to manage the two forms?
-
At first I thought one controller to manage both forms but there is a problem – I don’t know how the controller can identify exactly which button was pressed (Save or Add) to do the proper thing. It can everytime update the two tables acting as the two buttons are pressed at the same, but I think that this would be unrational because most of the time only the one table will have changes.
-
Another idea is to repeat the same with Delete – to have two different controllers which to do some actions (update and persist) and then to redirect to the edit page with which I aim the user to feel like never leaving the url of the beginning page (the edit page).
-
What is the best way to manage this tasks?
SensioGeneratorBundlecan generate CRUD forms and controllers. It ships within Symfony Standard edition. You should look at it. Generated code is easily customizable and is well engineered.You have done the right choice. You could also put the delete button into a form with
method="delete"and do something like this into your controller:You could set different
method(edition:POST, creation:PUT).You could set different
actionand then do a redirection.