I have created admin grid for Image Slider in backend and need to add backend form for that grid.
If I click Add New slide or edit button, it needs to show a form. So Suggest me, how to create a backend form and how to link it with the grid?
adminadminformmagento2.2PHP
I have created admin grid for Image Slider in backend and need to add backend form for that grid.
If I click Add New slide or edit button, it needs to show a form. So Suggest me, how to create a backend form and how to link it with the grid?
Best Answer
If you just need to create an admin form, have a look at here.
https://www.pierrefay.com/magento2-training/form-component-backend-crud-admin.html
To create our Form, we will first create the newAction action in our controller like this:
We load and then display the layout that will contain the form. We check if we receive the parameter "contact" (if the form is sent), if yes then we save the contact in the database . Logically, we will now create the layout
In this layout, we just tell him to look for our layout contacts_text_edit. We create the layout file for editing
Creating the file uiComponent for creation our form in magento2 Here it is said to load a uiComponent named "pfay_contacts_form", ( remember we did the same for the grid in the previous tutorial). We will, therefore, create the form in this uiComponent form. So let's create our uiComponent file for our form
The datasource of our magento2 form takes here our class "Pfay\Contacts\Model\Contact\DataProvider" so we will create it. So create
It is this file that allows our fields to be automatically mapped to the database. The so-called "dataBinding". Here we called our fieldset "contact", so we pass our Contact object in the loadedData array that we return. Configuring our form buttons Under magento2, in the forms, we define classes for buttons like what we did in our uiComponent:
We will create our files: Create a GenericButton: The GenericButton is the element that allows other buttons to exist. This is the base that extends the other buttons.
Create a button to save our magento2 form Create the file
In which you just configure the label of the button, the associated event and the form-role that automatically triggers events js for magento2.
Create a button to delete an object using our form Then create the file to delete an item from our formular
Here it is more or less pariel but for the suppression:
Create a reset button to reset our magento2 form
Create a reset button to save our form
And here are !! Our buttons are created and theoretically, everything should work :) Create our delete action We create our delete action to remove an object from the Magento grid like this:
Here is another tutorial for your reference. https://webkul.com/blog/create-ui-form-magento2-part-1/