[Formsess-devel] drive the validation from Business layer (3): input tag
Status: Beta
Brought to you by:
mrkatana
|
From: Raoul P. <pie...@wa...> - 2004-06-05 07:35:57
|
Hello,
The third request is about the Formsess Input tag. Now we really start =
with the subject.
At the moment, the type of an input tag must be coded in the template. =
And so you can't easily shift between radio and checkbox types for =
exemple.
To do it we need to delay the type controls in FormsessTagInput::getTag.
The changes would be:
- create the smarty_function_fs_input function:
function smarty_function_fs_input($params, &$smarty) {
$type =3D $params['type'];
$fileName =3D 'fs_input_' .$type;
$functionName =3D 'smarty_function_'.$fileName;
unset($params['type']); =20
require_once $smarty->_get_plugin_filepath('function',$fileName);
=20
return $functionName($params, $smarty);
}=20
- remove the type controls from FormsessTagInput::getTag, that is the =
class becomes:
class FormsessTagInput extends FormsessTag {
=20
function getTag() {
$type =3D 'input_' . $this->getAttributeValue('type');
$this->setName($type);
=20
// create the string with the smarty delimiters and all =
attributes
$string =3D 'fs_input' .$this->glueAttributes(); // 'fs_input' =
here without tail underscore
return $this->getCaptures() . $this->smartyEmbed($string);
}
}
- convert string to array in smarty_function_fs_input_checkbox:
function smarty_function_fs_input_checkbox($params, &$smarty) {
[...] =20
if (in_array($value, (array)$itemValues)) {
$params['checked'] =3D 'checked';
}
[...] =20
- put the radio control in smarty_function_fs_input_radio:
=20
function smarty_function_fs_input_radio($params, &$smarty) {
$fs =3D& $GLOBALS['__fs_current'];
$name =3D $params['name'];
// the "value" attribute is mandatory for a radio button
if ( (! isSet($params['value']) || ($params['value'] =3D=3D '')) =
) {
return '[fs:radio] the value is mandatory for a <fs:input =
type=3D"radio"> tag';
}
[...] =20
Regards
Pierre
|