Skip to content

Instantly share code, notes, and snippets.

@e06widu
Last active December 19, 2015 21:09
Show Gist options
  • Save e06widu/6018171 to your computer and use it in GitHub Desktop.
Save e06widu/6018171 to your computer and use it in GitHub Desktop.
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// Include dependancy of the main model form
jimport('joomla.application.component.modelform');
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
// Include dependancy of the dispatcher
jimport('joomla.event.dispatcher');
/**
* HelloWorld Model
*/
class MyResourceListModeljoinwithus extends JModelForm
{
/**
* @var object item
*/
protected $data;
/**
* Get the data for a new qualification
*/
public function getForm($data = array(), $loadData = true)
{
$app = JFactory::getApplication('site');
// Get the form.
$form = $this->loadForm('com_myresourcelist.joinwithus', 'joinwithus', array('control' => 'jform', 'load_data' => true),true);
if (empty($form)) {
return false;
}
return $form;
}
protected function loadFormData()
{
return $this->getData();
}
public function getData()
{
if ($this->data === null) {
$this->data = new stdClass();
$app = JFactory::getApplication();
$params = JComponentHelper::getParams('com_myresourcelist');
// Override the base user data with any data in the session.
$temp = (array)$app->getUserState('com_myresourcelist.joinwithus.data', array());
foreach ($temp as $k => $v) {
$this->data->$k = $v;
}
// Unset the Email.
unset($this->data->email);
// Get the dispatcher and load the users plugins.
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('user');
// Trigger the data preparation event.
$results = $dispatcher->trigger('onContentPrepareData', array('com_myresourcelist.joinwithus', $this->data));
// Check for errors encountered while preparing the data.
if (count($results) && in_array(false, $results, true)) {
$this->setError($dispatcher->getError());
$this->data = false;
}
}
return $this->data;
}
//Nwely added method for saving data
public function updItem($data)
{
// set the variables from the passed data
$fname = $data['fname'];
$lname = $data['lname'];
$age = $data['age'];
$city = $data['city'];
$telephone = $data['telephone'];
$email = $data['email'];
$comments = $data['comments'];
// set the data into a query to update the record
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->clear();
$db =& JFactory::getDBO();
$query = "INSERT INTO #__joinwithus ( `id`, `firstname`, `lastname`, `age`, `city`, `telephone`, `email`, `comment`)
VALUES (NULL,'" . $fname . "','" . $lname . "','" . $age . "','" . $city . "','" . $email . "','" . $telephone . "','" . $comments . "')";
$db->setQuery((string)$query);
if (!$db->query()) {
JError::raiseError(500, $db->getErrorMsg());
return false;
} else {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment