[TYPO3-project-formidable] include dynamic XML

Jerome Schneider j.schneider at ameos.com
Mon Mar 26 17:11:12 CEST 2007


Hello Tonni,

What you need is the xmlbuilder, which is the (really simplier) 
equivalent of DOM in javascript

This feature is not published for the moment as it is still in 
developpment, but here is how to add it to your version of formidable 
until next release:


STEP 1:
in File: ameos_formidable/api/class.tx_ameosformidable.php
in method: _compileConf
-> just before      return $aConf;   add this line:



$aConf = $this->_insertXmlBuilder($aConf);



---------------------------------------------

STEP 2:
in the same file
somewhere in the class definition, add this method

function _insertXmlBuilder($aConf, $aTemp = array()) {
	
	reset($aConf);
	while(list($key, $val) = each($aConf)) {

		if(is_array($val)) {

			if(t3lib_div::isFirstPartOfStr($key, "xmlbuilder")) {

				$aTemp = $this->array_add(
					$this->_callUserObj($val),
					$aTemp
				);

			} else {
				$aTemp[$key] = $this->_insertXmlBuilder($val);
			}
		}
		else {
			$aTemp[$key] = $val;
		}
	}
	
	return $aTemp;
}



--------------------------------------------

That's all for the patch.

USAGE:
Place an xmlbuilder tag wherever you want in the XML ( in your case we 
need renderlets, so it will be in <elements></elements> tag )
Like this:

<xmlbuilder>
	<userobj>
		<php><![CDATA[

			$aXml = array();

			$aSomeCollection = array(
				"lboxone" => "My first listbox",
				"lboxtwo" => "My second one",
				"lboxthree" => "My third one",
			);

			reset($aColumns);
			while(list($sName, $sLabel) = each($aSomeCollection)) {
				
				$aXml["renderlet-somenamespace-" . $sName] = array(
					"type" => "LISTBOX",
					"name" => $sName,
					"label" => $sLabel,
					"data" => array(
						"items" => $this->_arrayToRdtItems(
							array(
								"option_a" => "I prefer A",
								"option_b" => "Gimme a B",
								"option_rand" => "Random is better: " . rand(),
							)
						)
					),
					/* whatever config you need ... */
				);

			}

			return $aXml;

		]]></php>
	</userobj>
</xmlbuilder>



All the possible xml configuration described in the Formidable 
documentation can be translated to a php array for dynamic form buiding 
that way.

Hope this helps ( and does not sux too much :D )

Jerome Schneider

PS: the php method and xml exemples are also included in attachements to 
this post for your convenience


Tonni Aagesen a écrit :
> Hi,
> 
> I'm currently working on integrating paymentlib into seminars, which is 
> using formidable to render form fields etc.
> 
> Depending on selected payment method(s), paymentlib returns an array 
> with some information on form fields needed by the paymentmethod. Since 
> there is a variable number of fields, they can not be defined in the XML 
> for formidable.
> 
> So, I need to add formfields to the XML dynamically. I checked out the 
> code for "includeXML", but this only seems to read from a file.
> 
> Any hints on how to achieve my goal ?
> 
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: xmlbuilderpatch.php
Url: http://lists.netfielders.de/pipermail/typo3-project-formidable/attachments/20070326/4874a6b4/attachment.pot 


More information about the TYPO3-project-formidable mailing list