joomla form validation in controller

// GET THE DATA FROM THE POSTED FORM
$data = JRequest::getVar(‘jform’, array(), ‘post’, ‘array’);
// USE THE MODEL CLASS TO LOAD THE FORM OBJECT.
$form = $this->getForm($data);
// GET THE VALUE OF A SPECIFIC FIELD
$a = $form->getValue(‘a’);
// IF THE VALUE OF a IS ZERO, THEN b IS NOT REQUIRED
if((int)$a == 0){
$form->setFieldAttribute(‘b’, ‘required’, ‘false’);
}
// VALIDATE THE FORM BASED ON CHANGES YOU MADE
$form->validate($data);

Advertisements

model call from another controller

JModel::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
$model =& JModel::getInstance('Article', 'ContentModel', array('ignore_request'=>true));

$appParams = JFactory::getApplication()->getParams();
$model->setState('params', $appParams);

$item =& $model->getItem($id);