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

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"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
$smarty->assign("now",time());
$smarty->display("index.tpl");
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"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
$smarty->assign("now",time());
$smarty->display("index.tpl");
function insert_foo($args)