This post is 3ed part of my lesson series.I strongly recommend you to follow my previous posts about joomla custom forms to continue with this lesson.
In this post we’ll discuss about how to save form data into database.
In our installation component contains installation sql file named install.mysql.utf8 in administrator –> components –> com_myresourcelist –> sql
After installing com_myresourcelist into your joomla project new database table will add into your database.Ti named as yourprefix_joinwithus .You can check it by using phpmyadmin in your server.
Let’s create controller class for join with us inside .Most important thing is naming the php class.In my example it named as MyResourceListControllerJoinWithUs.
It handles the submit event of the form.To saving data on database insert query will contain on model class.It is calling from controller class submit event. Please read comments on controller class and saving data method will call as $model->updItem($data);
Updated medel class(components->com_myresourcelist->models->joinwithus.php) as follows.
Now you can save data using your front end form.After submitting data notification message will be seen in the screen.
Form Validation
If you need to validate last name as requird field, you just need to update components –> com_myresourcelist –> models –> forms –> joinwithus.xml as follows.
<field name="lname" type="text" required="true" description="COM_MYRESOURCELIST_FORM_DESC_LNAME"
label="COM_MYRESOURCELIST_FORM_LBL_LNAME" size="50" />
this will add validation method to submit data form.
Next post I hope to show you how to show saved data on front end table.