Monday, May 27, 2013

Joomla 2.5 MVC Frontend Custom Form - Step3

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.

9 comments:

  1. Great blog!
    Would live to see a version for properly using jform in a module (forntend forms)..

    ReplyDelete
  2. Getting 500 error:

    invalid controller: name='joinwithus', format=''

    when submitting the form

    ReplyDelete
    Replies
    1. 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.

      Delete
    2. You need to put controller in site\controllers folder and then add this folder to the main xml file (joinwithus.xml in components root)

      Delete
  3. Thanks again - would be great to have something similar for Joomla module!

    ReplyDelete
  4. thank for your articles. I wish you can continue this tutorial.

    ReplyDelete
    Replies
    1. Thanks :) I hope to continue further more.

      Delete
  5. the class of the controller, where do I put?

    ReplyDelete