Save contact form data magento database

This tutorial explains how to save contact form data magento database. Here it explains in detail how to extend the magento contact form code to save the data to the table on form submissions.

Please refer the tutorial which explains how to mass import magento products from the CSV and develop magento admin module tutorial.

This module save the data to database as show below.

save contact form data magento table

Step by step explanation

  • File Structure
  • Enable Magento module
  • Create Contact Table
  • Rewrite post action – Controller
  • Create Models
  • Config xml file – magento module
  • Save contact form data magento database

File Structure

Create the following the files inside the app/code/local folder.

save-contact-form-data-magento-database

Enable Magento Module

Click here and find the code for enabling module.

Create contact table

In the previous step we enabled the magento module from the backend. This stage creates a custom table for saving the data to database. Please check here for table install script.

Rewrite post action – Controller

This step rewrite the postAction() function of the controller.Add the following code to controller postAction() function.

save contact form data magento controller

Click here for full controller postAction() code.

Create Models

The model saves the data to the database.For that we need to create the custom model. Create the model files and click here for model codes.

Config xml file – magento module

ln the above steps we enabled the module, rewrite the controller file and create the model files. This step we need to include the following above files in the config.xml file.Please click here to get the config file.

Download the complete code.

Share this Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *

*