|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
TommyD Smarty Rookie
Joined: 20 Feb 2004 Posts: 18
|
Posted: Wed Oct 13, 2004 10:27 am Post subject: Easy checkbox handling |
|
|
usage: {checkbox name="foo" label=#foo# checked=$foo}
Produces a checkbox and a label on the right. You no longer need to do any isset($_REQUEST['foo']) to determine if it was marked or not... nitty, gritty, eh?
Code: | <?php
/**
* The following code is released under LGPL available at
* http://www.gnu.org/copyleft/lesser.html.
*
* You may not modify or remove this header.
*
* (c) 2004 Thomas Keller <me@thomaskeller.biz>
*/
/**
* Smarty {checkbox} function plugin
*
* Type: function<br>
* Name: checkbox<br>
* Input:<br>
* - name (required) - string
* - label (required) - string
* - checked (optional) - boolean
*
* Purpose: Shorthand for creating checkboxes with <label> tag and
* checked mechanism
* @param array
* @param Smarty
* @return string
*/
function smarty_function_checkbox($params, &$smarty)
{
if (!isset($params['name']) || empty($params['name'])) {
$compiler->_syntax_error("checkbox: 'name' parameter not given or empty.", E_USER_WARNING);
return;
}
if (!isset($params['label']) || empty($params['label'])) {
$compiler->_syntax_error("checkbox: 'label' parameter not given or empty.", E_USER_WARNING);
return;
}
$html = "<input type=\"checkbox\" name=\"[[NAME]]\" id=\"[[NAME]]\"";
if (isset($params['checked']) && $params['checked']==1)
{
$html .= " checked=\"checked\"";
}
$html .= " value=\"1\">\n<label for=\"[[NAME]]\">";
$html .= $params['label'];
$html .= "</label>\n";
return str_replace("[[NAME]]",$params['name'],$html);
}
?> |
_________________ Administrator / Developer on http://www.musicmademe.com
- http://thomaskeller.biz |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|