mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
Added ability to pass 'options' attribute to html_options.
This commit is contained in:
@@ -155,12 +155,20 @@ function smarty_func_html_options()
|
|||||||
|
|
||||||
extract(func_get_arg(0));
|
extract(func_get_arg(0));
|
||||||
|
|
||||||
settype($output, 'array');
|
|
||||||
settype($values, 'array');
|
|
||||||
settype($selected, 'array');
|
|
||||||
|
|
||||||
$html_result = "";
|
$html_result = "";
|
||||||
|
|
||||||
|
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++) {
|
for ($i = 0; $i < count($output); $i++) {
|
||||||
/* By default, check value against $selected */
|
/* By default, check value against $selected */
|
||||||
$sel_check = $values[$i];
|
$sel_check = $values[$i];
|
||||||
@@ -174,6 +182,7 @@ function smarty_func_html_options()
|
|||||||
$html_result .= " selected";
|
$html_result .= " selected";
|
||||||
$html_result .= ">".$output[$i]."</option>\n";
|
$html_result .= ">".$output[$i]."</option>\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($print_result)
|
if ($print_result)
|
||||||
print $html_result;
|
print $html_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"),
|
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||||
|
|
||||||
$smarty->assign("now",time());
|
|
||||||
|
|
||||||
$smarty->display("index.tpl");
|
$smarty->display("index.tpl");
|
||||||
|
|
||||||
function insert_foo($args)
|
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"),
|
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||||
|
|
||||||
$smarty->assign("now",time());
|
|
||||||
|
|
||||||
$smarty->display("index.tpl");
|
$smarty->display("index.tpl");
|
||||||
|
|
||||||
function insert_foo($args)
|
function insert_foo($args)
|
||||||
|
Reference in New Issue
Block a user