Added ability to pass 'options' attribute to html_options.

This commit is contained in:
andrey
2001-01-31 22:55:52 +00:00
parent e66a4ac648
commit f9878b7316
3 changed files with 25 additions and 20 deletions

View File

@@ -155,24 +155,33 @@ 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 = "";
for ($i = 0; $i < count($output); $i++) { settype($selected, 'array');
/* By default, check value against $selected */ if (isset($options)) {
$sel_check = $values[$i]; settype($options, 'array');
$html_result .= "<option"; foreach ($options as $key => $value) {
if ($i < count($values)) $html_result .= "<option value=\"$key\"";
$html_result .= " value=\"".$values[$i]."\""; if (in_array($key, $selected))
else $html_result .= " selected";
$sel_check = $output[$i]; /* if more outputs than values, then $html_result .= ">$value</option>\n";
check output against $selected */ }
if (in_array($sel_check, $selected)) } else {
$html_result .= " selected"; settype($output, 'array');
$html_result .= ">".$output[$i]."</option>\n"; 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) if ($print_result)

View File

@@ -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)

View File

@@ -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)