I am trying to find the preferred way to save form data using joomla API methods. I am trying to save data with an ajax-call. First i tried just calling the components standard save method, calling:
index.php?option=com_whatever&view=wdata&task=save // ...etc
This works, sort of, but I cannot find a way to verify the call actually worked.
Now I'm trying to use the model functions from the new and very nice ajax-plugin in joomla 3.3, but I'm unsure what is the right approach. I can do something like this:
function onAjaxSaveWData(){
if(!JSession::checkToken()) return 0; // checking the token
$in=JFactory::getApplication->input;
$data=$in->get('jform',array(),'ARRAY'); //this is unfiltered input?!
JLoader::register('WhateverModelWData', $whatevermodelpath);
$model = new WhateverModelWData();
$model->save($data);
}
The only problem with this approach is it's not working. The save function fails with an error:
Call to a member function getKeyName() on a non-object in libraries/legacy/model/admin.php on line 1064
In addition to this not working, it would have not filtered the data before insertion.
I would think $model->validate($model->getForm(), $data)
would do the trick, but also $model->getForm()
fails miserably, so I'm stuck. Can anyone help me out?