Merging multiple forms

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
NekaraNef
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Thu Sep 15, 2011 2:11 pm

Merging multiple forms

Post by NekaraNef » Thu Sep 15, 2011 2:29 pm

Greetings,

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);
That didn't work either, because those fields were thrown right away:

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;
		}
Of course my element isn't an instance of JXMLElement yet! I'm trying to add it right now, aren't I?

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.']');
            }
Now, so far, everything's on the up and up. That is, the objects are created properly and they contain the proper xml, fields, and so forth. array_merge_recursive() looked pretty promising at first, but it looses the stdClass, which is important to actually display the form later on.

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?

izharaazmi
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun Apr 10, 2011 9:31 am

Re: Merging multiple forms

Post by izharaazmi » Mon May 07, 2012 2:32 pm

I may be too late, but this is when I notice this post.

Well here is my solution:

I am merging the plugin params into the default form, inside a Model.

Code: Select all

	protected function preprocessForm(JForm $form, $data, $group = 'plugin')
	{
		jimport('joomla.filesystem.file');
		jimport('joomla.filesystem.folder');

		// Initialise variables.
		$lang = JFactory::getLanguage();
		$app  = JFactory::getApplication();

		$formFile 	= JPath::clean( JPATH_SITE.DS.'plugins'.DS.'content'.DS.'emailcloak'.DS.'emailcloak.xml' );

		if (file_exists($formFile))
		{
			// Get the plugin form's config section.
			if (!$form->loadFile($formFile, false, '//config'))
			{
				throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
			}
			
			// Attempt to load the xml file.
			if (!$xml = simplexml_load_file($formFile))
			{
				throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
			}
		}
		
		// Trigger the default form events.
		parent::preprocessForm($form, $data, $group);
	}
And... thats all to have the fields from the two xml forms together.

Hope this helps at least somebody!

User avatar
Croc
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Mon Nov 17, 2008 10:20 pm
Location: Greece
Contact:

Re: Merging multiple forms

Post by Croc » Thu May 28, 2015 1:39 pm

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<form>
	<fieldset name="tablefields">
		<field name="id" type="text" label="COMPO_FORM_LBL_ID" description="COMPO_FORM_DESC_ID" default="0" readonly="1" class="inputbox readonly" />
		<field name="name" type="text" filter="string" label="COMPO_FORM_LBL_NAME" description="COMPO_FORM_DESC_NAME" default="" required="1" class="inputbox" />
		.......
		<field name="params" type="pluginparams" filter="string" label="COMPO_FORM_LBL_PARAMS" description="COMPO_FORM_DESC_PARAMS" default="" />
	</fieldset> 
</form>
I'm wondering how I can store the parameters of XML of plugin at "params" field, I have created a custom type named "pluginparams" and I will try to parse the XML.
Also I would like on editing view to show the Fileds of plugin as component fields also to override the parameters (Global,Yes, No)
http://web-expert.gr/en - Joomla Hosting & Extensions


Locked

Return to “Joomla! 2.5 Coding”