Created
August 3, 2013 16:07
-
-
Save rdeutz/6146981 to your computer and use it in GitHub Desktop.
adding form fields on the fly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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