User Rating: 1 / 5

Star ActiveStar InactiveStar InactiveStar InactiveStar Inactive

After building a successful form  And then later we have Save button to save the form data into the database.

- Start editing files in the folder hello.php controllers add method save. 



function save()
        JRequest::checkToken() or die('Invaild Token');

        $data = $this->input->post->get('jform', array(), 'array');
        $model = $this->getModel('hello');

        if($model->save($data)) {
                $this->setMessage('Save successfully');
        } else {
                JError::raiseWarning('', 'Save failed<br />'.implode('<br />', $model->getErrors()));



- Modify the files in the folder hello.php models by adding method save.


function save($data) 
        $db = JFactory::getDbo();
        $obj = (object) $data;
        try {               
                $db->insertObject('#__helloworld_hello', $obj, 'id');
        } catch (RuntimeException $exc) {            
                return false;
        return true;





Chapter 11 - Display data from database Component Development