[TYPO3-project-formidable] Improvements

Jérémy Lecour jeremy.lecour at gmail.com
Tue Jul 25 11:38:23 CEST 2006


Hi,

I've noticed some stuff that could be easily improved in FORMidable

In the "Valid XHTML" category, there are some things :
- tags should be written lowercase,
- all the params must have a value CHECKED should be checked="checked"
- a space and a slash must be at the end of non closing tag <BR>
should be <br />
For these, I won't geive a patch, but it's easy to search/replace in
the source code

In the "real improvements" category, I'd like to point to label tags.
In xHTML we are invited to use labels abd FORMidable is using them,
but only in a specific way, there are others

Some people like to have the label (and his text) outside the form
tag, on the left, or maybe on the right. Some other like to have the
label tag surrounding the form tag, with the text before or after.
An easy way to allow that is to add a param in the element
configuration. In my own modifications, I've named it "input_pos" with
4 possible values : in_left/in_right/out_left/out_right and the
default value could be out_right.

Then I use a "switch" test to format the output of the form tag and its label.

These modifications could be applied to any form tag that accepts a label tag.

Here is the modified "_render()" function for the Checkbox renderlet

------------------ class.tx_ameosformidablerdtcheckbox.php at 33 ------------------
	function _render($aFormData = array()) {
		// on doit rendre un groupe de controles checkboxes

		$aHtml = array();
		
		$label = $this->oForm->_getLLLabel($this->aElement["label"]);
		$aItems = $this->_getItems();
		
		$input_pos = $this->oForm->_navConf("/data/input_pos/", $this->aElement);
		
		reset($aItems);
		while(list($index, $aItem) = each($aItems)) {
			$value = $aItem["value"];
			$caption = $this->oForm->_getLLLabel($aItem["caption"]);

			// on crée le nom du controle
			$name = $this->_getElementHtmlName() . "[" . $index . "]";

			$checked = "";
			$aChecked = array();

			// on récupère la valeur soumise
			if($this->oForm->oDataHandler->_isSubmitted() ||
array_key_exists($this->_getName(), $aFormData))
			{
				if(is_array($aFormData[$this->_getName()]))
				{ $aChecked = $aFormData[$this->_getName()];}
			}
			else
			{ $aChecked = $this->_getDefaultValue();}

			if(is_array($aChecked) && in_array($value, $aChecked))
			{ $checked = ' checked="checked"';}

			$sInput = '<input type="checkbox" name="' . $name . '" id="' .
$name . '" value="' . $value . '" ' . $checked . $this->_getEvents() .
' />';
				
			$sLabelStart = '<label for="' . $name . '">';
			$sLabelEnd = '</label>';
			
			switch ($input_pos) {
				case 'in_left' :
					$aHtml[] = $sLabelStart . $sInput . $caption . $sLabelEnd;
				break;
				
				case 'out_left' :
					$aHtml[] = $sInput . $sLabelStart . $caption . $sLabelEnd;
				break;
				
				case 'in_right' :
					$aHtml[] = $sLabelStart . $caption . $sInput . $sLabelEnd;
				break;
				
				case 'out_right' :
				default :
					$aHtml[] = $sLabelStart . $caption . $sLabelEnd . $sInput;
				break;
			}
		}
		
		return $this->oForm->oRenderer->_displayLabel($label,$this->_getElementHtmlName())
. implode("<br>\n", $aHtml);
	}
------------------

You will notice that I've also modified "_displayLabel()" by adding a
second parameter, that can be ommited. If a string is passed as a
second parameter, it is used as "for" parameter in the generated label
tag.

------------------ class.mainrenderer.php at 319 ------------------
function _displayLabel($label,$elementname='') {
	return ($this->bDisplayLabels && (trim($label) != "")) ?
'<label'.(trim($elementname) != "" ? ' for="'.$elementname.'"' :
'').'>' . $label . '</label>' : "";
}
------------------


I've made some other modifications, but don't remember where !! some
day I'll make a real diff against the 'official' source code ;-)
-- 
Jérémy Lecour : <mailto:jeremy.lecour at gmail.com>
webdesigner, webmaster et développeur web
Trésorier du PLUG : Provence Linux User Group
http://www.plugfr.org/



More information about the TYPO3-project-formidable mailing list