Source for file function.pnformradiobutton.php
Documentation is available at function.pnformradiobutton.php
* @copyright (c) 2006, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: function.pnformcheckbox.php 22138 2007-06-01 10:19:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_Template_Plugins
* Plugin to generate a radiobutton for selecting one-of-X.
* Usage with fixed number of radiobuttons:
* <!--[pnformradiobutton id=yesButton dataField=ok]--> <!--[pnformlabel text=Yes for=yesButton]--> <br/>
* <!--[pnformradiobutton id=noButton dataField=ok]--> <!--[pnformlabel text=No for=noButton]-->
* The above case sets 'ok' to either 'yesButton' or 'noButton' in the hashtable returned
* by {@link pnFormRender::pnFormGetValues()}. As you can see the radiobutton defaults to using the ID for the returned value
* in the hashtable. You can override this by setting 'value' to something different.
* You can also enforce a selection:
* <!--[pnformradiobutton id=yesButton dataField=ok mandatory=1]--> <!--[pnformlabel text=Yes for=yesButton]--> <br/>
* <!--[pnformradiobutton id=noButton dataField=ok mandatory=1]--> <!--[pnformlabel text=No for=noButton]-->
* If you have a list of radiobuttons inside a for/each loop then you can set the ID to something from the data loop
* <!--[foreach from=$items item=item]-->
* <!--[pnformradiobutton id=$item.name dataField=item mandatory=true]--> <!--[pnformlabel text=$item.title for=$item.name]-->
* The value returned in pnFormGetValues() when this radio button is checked.
* The current state of the radio button
* Enable or disable read only mode
* Data field name for looking up initial data
* The name stored here is used to lookup initial data for the plugin in the render's variables.
* Defaults to the ID of the plugin. See also tutorials on the Zikula site.
* Enable or disable use of $dataField
* Group name for this input
* The group name is used to locate data in the render (when databased) and to restrict which
* plugins to do validation on (to be implemented).
* @see pnFormRender::pnFormGetValues()
* @see pnFormRender::pnFormIsValid()
* Radiobutton selection group name
* Validation indicator used by the framework.
* The true/false value of this variable indicates whether or not radiobutton selection is valid
* (a valid (set of) radiobuttons satisfies the mandatory requirement).
* Use {@link pnFormRadioButton::setError()} and {@link pnFormRadioButton::clearValidation()}
* Enable or disable mandatory check
* By enabling mandatory checking you force the user to check one of the radio buttons on the page
* that shares the same groupName.
* Enable or disable auto postback
* Auto postback means "generate a server side event when selection changes".
* If enabled then the event handler named in $onSelectedIndexChanged will be fired
* in the main form event handler.
* Name of checked changed method
* @var string Default is "handleCheckedChanged"
* Error message to display when input does not validate
* Use {@link pnFormRadioButton::setError()} and {@link pnFormRadioButton::clearValidation()}
* Text label for this plugin
* This variable contains the label text for the radiobutton. The {@link pnFormLabel} plugin will set
* this text automatically when it is a label for this input.
return __FILE__ ; // FIXME: should be found in smarty's data???
function create(&$render, $params)
// Load all special and non-string parameters
// - the rest are fetched automatically
function load(&$render, &$params)
$this->loadValue($render, $render->get_template_vars());
if ($this->group == null)
$render->pnFormAddValidator($this);
$idHtml = $this->getIdHtml();
$readOnlyHtml = ($this->readOnly ? " disabled=\"disabled\"" : '');
$checkedHtml = ($this->checked ? " checked=\"checked\"" : '');
$postbackHtml = " onclick=\"" . $render->pnFormGetPostBackEventReference($this, '') . "\"";
$attributes = $this->renderAttributes($render);
$result = "<input type=\"radio\" value=\"{ $this->value}\" class=\"radio\"{ $idHtml}{ $nameHtml}{ $readOnlyHtml}{ $checkedHtml}{ $postbackHtml}{ $attributes}/> ";
function raisePostBackEvent(&$render, $eventArgument)
$args = array('commandName' => null, 'commandArgument' => null);
function decode(&$render)
// Do not read new value if readonly (evil submiter might have forged it)
$this->checked = (FormUtil::getPassedValue($this->groupName, null, 'POST') === $this->value ? true : false);
function validate(&$render)
$firstRadioButton = null;
$this->setError(_PNFORM_MANDATORYSELECTERROR);
function findCheckedRadioButton(&$render, &$firstRadioButton)
$lim = count($render->pnFormPlugins);
for ($i= 0; $i< $lim; ++ $i)
function findCheckedRadioButton_rec(&$firstRadioButton, &$plugin)
if (is_a($plugin, 'pnFormRadioButton') && $plugin->groupName == $this->groupName)
$plugin->validationChecked = true;
if ($firstRadioButton == null)
$firstRadioButton = $plugin;
$lim = count($plugin->plugins);
for ($i= 0; $i< $lim; ++ $i)
function clearValidation(&$render)
function saveValue(&$render, &$data)
if ($this->group == null)
if (!array_key_exists($this->group, $data))
$data[$this->group] = array();
function smarty_function_pnformradiobutton($params, &$render)
return $render->pnFormRegisterPlugin('pnFormRadioButton', $params);
|