Skip to content

Instantly share code, notes, and snippets.

@rdeutz
Created August 3, 2013 16:07
Show Gist options
  • Save rdeutz/6146981 to your computer and use it in GitHub Desktop.
Save rdeutz/6146981 to your computer and use it in GitHub Desktop.
adding form fields on the fly
Manipulation a JForm is easy the best place to add fields is to use the preprocessForm function
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
// Add some needed hidden fields
$fields = array('id','cid');
foreach ($fields AS $field)
{
$element = new SimpleXMLElement('<field></field>');
$element->addAttribute('name', $field);
$element->addAttribute('type', 'hidden');
$element->addAttribute('default', '0');
$element->addAttribute('readonly', 'true');
$element->addAttribute('class', 'readonly');
$form->setField($element);
}
parent::preprocessForm($form, $data, $group);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment