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.
good tut tnx
ReplyDeleteGreat blog!
ReplyDeleteWould live to see a version for properly using jform in a module (forntend forms)..
Getting 500 error:
ReplyDeleteinvalid controller: name='joinwithus', format=''
when submitting the form
Have you used same files in my custom component or you used your own naming convention.If you used your own naming convention please change Controller name and see.
DeleteYou need to put controller in site\controllers folder and then add this folder to the main xml file (joinwithus.xml in components root)
DeleteThanks again - would be great to have something similar for Joomla module!
ReplyDeletethank for your articles. I wish you can continue this tutorial.
ReplyDeleteThanks :) I hope to continue further more.
Deletethe class of the controller, where do I put?
ReplyDelete