mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
commit checkboxes, update radios
This commit is contained in:
1
NEWS
1
NEWS
@@ -3,6 +3,7 @@
|
|||||||
- added << >> <> support to if statments (SMK, Monte)
|
- added << >> <> support to if statments (SMK, Monte)
|
||||||
- fix _assign_smarty_interface to not overwrite keys
|
- fix _assign_smarty_interface to not overwrite keys
|
||||||
other than 'request' (Jerome Poudevigne, Monte)
|
other than 'request' (Jerome Poudevigne, Monte)
|
||||||
|
- added html_checkboxes to distribution (Christopher Kvarme, Monte)
|
||||||
- added html_radios to distribution (Christopher Kvarme, Monte)
|
- added html_radios to distribution (Christopher Kvarme, Monte)
|
||||||
- fixed string_format modifier args (wrong order) (Paul
|
- fixed string_format modifier args (wrong order) (Paul
|
||||||
Lockaby, Monte)
|
Lockaby, Monte)
|
||||||
|
61
libs/plugins/function.html_checkboxes.php
Normal file
61
libs/plugins/function.html_checkboxes.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Smarty plugin
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* File: function.html_checkboxes.php
|
||||||
|
* Type: function
|
||||||
|
* Name: html_checkboxes
|
||||||
|
* Version: 1.0
|
||||||
|
* Date: 24.Feb.2003
|
||||||
|
* Purpose: Prints out a list of checkbox input types
|
||||||
|
* Input: name (optional) - string default "checkbox"
|
||||||
|
* values (required) - array
|
||||||
|
* checked (optional) - array default not set
|
||||||
|
* separator (optional) - ie <br> or
|
||||||
|
* output (optional) - without this one the buttons don't have names
|
||||||
|
* Author: Christopher Kvarme <christopher.kvarme@flashjab.com>
|
||||||
|
* Credits: Monte Ohrt <monte@ispi.net>
|
||||||
|
* Examples: {html_checkboxes values=$ids output=$names}
|
||||||
|
* {html_checkboxes values=$ids name='box' separator='<br>' output=$names}
|
||||||
|
* {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
function smarty_function_html_checkboxes($params, &$smarty)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
|
||||||
|
$_html_result = '';
|
||||||
|
if(!isset($name)){
|
||||||
|
$name = 'checkbox';
|
||||||
|
}
|
||||||
|
settype($checked, 'array');
|
||||||
|
if (isset($checkboxes)) {
|
||||||
|
settype($checkboxes, 'array');
|
||||||
|
foreach ($checkboxes as $_key => $_val) {
|
||||||
|
$_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $checked, $separator);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
settype($output, 'array');
|
||||||
|
settype($values, 'array');
|
||||||
|
for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) {
|
||||||
|
$_html_result .= smarty_function_html_checkboxes_output($name, $values[$_i], $output[$_i], $checked, $separator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_html_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function smarty_function_html_checkboxes_output($name, $value, $output, $checked, $separator) {
|
||||||
|
$_output = '<input type="checkbox" name="' . htmlspecialchars($name) . '[]' .'" value="' . htmlspecialchars($value) . '"';
|
||||||
|
|
||||||
|
if (in_array($value, $checked)) {
|
||||||
|
$_output .= " checked=\"checked\"";
|
||||||
|
}
|
||||||
|
$_output .= '>' . $name . $separator . "\n";
|
||||||
|
|
||||||
|
return $_output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
@@ -2,69 +2,60 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Smarty plugin
|
* Smarty plugin
|
||||||
* ---------------------------------------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
* Type: function
|
* File: function.html_radios.php
|
||||||
* Name: html_radios
|
* Type: function
|
||||||
* Purpose: Prints the list of <input type="radio" tags generated from the passed parameters
|
* Name: html_radios
|
||||||
* Parameters: name [optional]- string default "radio"
|
* Version: 1.0
|
||||||
* checked [optional]- string default not set
|
* Date: 24.Feb.2003
|
||||||
* values [required] - array
|
* Purpose: Prints out a list of radio button input types
|
||||||
* separator[optional] - ie <br> or
|
* Input: name (optional) - string default "radio"
|
||||||
* output[optional] - without this one the buttons don't have names
|
* values (required) - array
|
||||||
* Author: Christopher Kvarme <christopher.kvarme@flashjab.com>
|
* checked (optional) - array default not set
|
||||||
* ---------------------------------------------------------------------------------------------
|
* separator (optional) - ie <br> or
|
||||||
|
* output (optional) - without this one the buttons don't have names
|
||||||
|
* Author: Christopher Kvarme <christopher.kvarme@flashjab.com>
|
||||||
|
* Credits: Monte Ohrt <monte@ispi.net>
|
||||||
|
* Examples: {html_radios values=$ids output=$names}
|
||||||
|
* {html_radios values=$ids name='choices' separator='<br>' output=$names}
|
||||||
|
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
|
||||||
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function smarty_function_html_radios($params, &$smarty)
|
function smarty_function_html_radios($params, &$smarty)
|
||||||
{
|
{
|
||||||
extract($params);
|
extract($params);
|
||||||
|
|
||||||
$html_result = '';
|
$_html_result = '';
|
||||||
if(!isset($name)){
|
if(!isset($name)){
|
||||||
$name = "radio";
|
$name = 'radio';
|
||||||
}
|
}
|
||||||
settype($checked, 'array');
|
settype($checked, 'array');
|
||||||
if (isset($radios)) {
|
if (isset($radios)) {
|
||||||
settype($radios, 'array');
|
settype($radios, 'array');
|
||||||
foreach ($radios as $key => $value) {
|
foreach ($radios as $_key => $_val) {
|
||||||
$html_result .= smarty_function_html_radios_optoutput($key, $value, $checked);
|
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $checked, $separator);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
settype($output, 'array');
|
settype($output, 'array');
|
||||||
settype($values, 'array');
|
settype($values, 'array');
|
||||||
for ($i = 0, $for_max = count($output); $i < $for_max; $i++) {
|
for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) {
|
||||||
if ($i < count($values)) {
|
$_html_result .= smarty_function_html_radios_output($name, $values[$_i], $output[$_i], $checked, $separator);
|
||||||
$html_result .= smarty_function_html_radios_optoutput($values[$i], $output[$i], $checked, $name, $separator);
|
|
||||||
} else {
|
|
||||||
$html_result .= smarty_function_html_radios_optoutput($output[$i], $output[$i], $checked, $name, $separator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $html_result;
|
return $_html_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_function_html_radios_optoutput($key, $value, $checked, $name, $separator) {
|
function smarty_function_html_radios_output($name, $value, $output, $checked, $separator) {
|
||||||
if(!is_array($value)) {
|
$_output = '<input type="radio" name="' . htmlspecialchars($name) . '[]' .'" value="' . htmlspecialchars($value) . '"';
|
||||||
$html_result = '<input type="radio" name="' . htmlspecialchars($name) . '" value="' .
|
|
||||||
htmlspecialchars($key) . '"';
|
if (in_array($value, $checked)) {
|
||||||
if (in_array($key, $checked))
|
$_output .= " checked=\"checked\"";
|
||||||
$html_result .= " checked";
|
|
||||||
$html_result .= '>' . htmlspecialchars($value) . $separator . "\n";
|
|
||||||
} else {
|
|
||||||
$html_result = smarty_function_html_radios_optgroup($key, $value, $checked, $name, $separator);
|
|
||||||
}
|
}
|
||||||
return $html_result;
|
$_output .= '>' . $name . $separator . "\n";
|
||||||
|
|
||||||
|
return $_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_function_html_radios_optgroup($key, $values, $checked) {
|
|
||||||
$optgroup_html = '<optgroup label="' . htmlspecialchars($value) . '">' . "\n";
|
|
||||||
foreach ($values as $key => $value) {
|
|
||||||
$optgroup_html .= smarty_function_html_radios_optoutput($key, $value, $checked);
|
|
||||||
}
|
|
||||||
$optgroup_html .= "</optgroup>\n";
|
|
||||||
return $optgroup_html;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user