Creating a backend form to add/edit data
If you want to add a new record or edit an existing record, it is possible to create a form to have a user friendly way to process the data. In this example, we will see how to create a form to edit an existing record. The path used to add a record will be as follows:
http://example.com/admin/sample/demolist/new/
This will require the controller name to be new, but as this is a reserved word in PHP, the class name used will be newAction
. The execute function is not only used to add a new record, but it can also be used to edit an existing record. In the following code, only the execute action is shown; see the sample code for the complete source.
Getting ready
In this recipe, we will add the option to add or edit records; for this, the route used in the previous chapter is used, only new controllers and blocks are shown.
How to do it…
Follow these steps to add a form to your module:
Add the controller:
Controller/Adminhtml/Demolist/NewAction.php
<?php namespace...