mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
Added ability to pass 'options' attribute to html_options.
This commit is contained in:
@@ -155,24 +155,33 @@ function smarty_func_html_options()
|
||||
|
||||
extract(func_get_arg(0));
|
||||
|
||||
settype($output, 'array');
|
||||
settype($values, 'array');
|
||||
settype($selected, 'array');
|
||||
|
||||
$html_result = "";
|
||||
|
||||
for ($i = 0; $i < count($output); $i++) {
|
||||
/* By default, check value against $selected */
|
||||
$sel_check = $values[$i];
|
||||
$html_result .= "<option";
|
||||
if ($i < count($values))
|
||||
$html_result .= " value=\"".$values[$i]."\"";
|
||||
else
|
||||
$sel_check = $output[$i]; /* if more outputs than values, then
|
||||
check output against $selected */
|
||||
if (in_array($sel_check, $selected))
|
||||
$html_result .= " selected";
|
||||
$html_result .= ">".$output[$i]."</option>\n";
|
||||
settype($selected, 'array');
|
||||
if (isset($options)) {
|
||||
settype($options, 'array');
|
||||
foreach ($options as $key => $value) {
|
||||
$html_result .= "<option value=\"$key\"";
|
||||
if (in_array($key, $selected))
|
||||
$html_result .= " selected";
|
||||
$html_result .= ">$value</option>\n";
|
||||
}
|
||||
} else {
|
||||
settype($output, 'array');
|
||||
settype($values, 'array');
|
||||
for ($i = 0; $i < count($output); $i++) {
|
||||
/* By default, check value against $selected */
|
||||
$sel_check = $values[$i];
|
||||
$html_result .= "<option";
|
||||
if ($i < count($values))
|
||||
$html_result .= " value=\"".$values[$i]."\"";
|
||||
else
|
||||
$sel_check = $output[$i]; /* if more outputs than values, then
|
||||
check output against $selected */
|
||||
if (in_array($sel_check, $selected))
|
||||
$html_result .= " selected";
|
||||
$html_result .= ">".$output[$i]."</option>\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($print_result)
|
||||
|
@@ -17,8 +17,6 @@ $smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
|
||||
$smarty->assign("now",time());
|
||||
|
||||
$smarty->display("index.tpl");
|
||||
|
||||
function insert_foo($args)
|
||||
|
@@ -17,8 +17,6 @@ $smarty->assign("Class",array(array("A","B","C","D"), array("E", "F", "G", "H"),
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
|
||||
$smarty->assign("now",time());
|
||||
|
||||
$smarty->display("index.tpl");
|
||||
|
||||
function insert_foo($args)
|
||||
|
Reference in New Issue
Block a user