I added custom tab in customer dashboard, using customer_account.xml
and i need to create form to this custom tab, if I click this custom tab, form will open in content area based on customer dashboard. So, which xml file I need to use to write a content.
Magento 2 – Form Creation for Custom Tab in Customer Dashboard
customerlayoutmagento-2.0magento2
Best Answer
I have done it like this , hope it will help you , i have extracted the script from my full module just to explain the flow of adding form and saving form data to database.
It is bit lengthy , but tried to explain in detail
For adding custom tab to customer dashboard
created a file view/frontend/layout/customer_account.xml with script
Then created the controller Controller/Profile/Index.php that will work for path customtab/profile with script
Now created the layout file at view/frontend/layout/customtab_profile_index.xml with script
Now i have to create the block Block/Store/Profile.php
And now the called phtml file view/frontend/templates/store/profile.phtml
And in the form you have to put form action like
I have just place the code to fetch the data , in this phtml file you can put your html code with your required fields.
Now for \Sample\Customtab\Model\ResourceModel\Stores\CollectionFactory used in block we have to create collection for it
Create a model Model/Stores.php with
The ResourceModel Model/ResourceModel/Stores.php with
Then Collection Model Model/ResourceModel/Stores/Collection.php with
Now have to create abstract class for save profile controller Controller/Profile.php
Now have to create profile save controller that will work on profile save form action Controller/Profile/Save.php
Hope i have included all the things. And it will work for you.