It's my first post here, and quite a big problem to tackle at the same time.
I'm trying to build a new component which should include a couple of fields for all 'known' languages. The first thing I tried was cycling through the fields and adding them using the setField() method from JForm. Unfortunately, I couldn't find any method to cycle through the fields. I tried building one, but I kept getting slapped with errors left and right. I figured I should try adding the fields in a more manual way:
Code: Select all
$form->setField($field,'_default',true);
$form->setField($field,'languages',true);
$form->setField($field,NULL,true);
Code: Select all
if (!($element instanceof JXMLElement)) {
// TODO: throw exception.
echo '<h1>help my new field is thrown out because its new</h1>';
return false;
}
Next I figured I could just build seperate forms and merge them.
A code snippet:
Code: Select all
$langList = JLanguage::getKnownLanguages();
$formLanguage = array();
foreach ($langList as $language)
{
$tag = $language['tag'];
$formLanguage[$tag] = $this->loadForm('com_vwcategories.vwcategory_language.'.$tag, 'vwcategory_language', array('control' => 'jform', 'load_data' => $loadData),'1');
$formLanguage[$tag]->setFieldAttribute('title', 'name', 'title['.$tag.']');
$formLanguage[$tag]->setFieldAttribute('description', 'name', 'description['.$tag.']');
$formLanguage[$tag]->setFieldAttribute('metadesc', 'name', 'metadesc['.$tag.']');
$formLanguage[$tag]->setFieldAttribute('metakey', 'name', 'metakey['.$tag.']');
}
And so I'm stuck and clear out of ideas. How do I merge these forms? Or how do I add the fields seperately? I haven't seen any functions in the JForm library that would allow me to do either. Suggestions?