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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s