Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Return an HTML <select> statment based on an array of options
- *
- * @returns string HTML output for select statement
- * @author Tamara Temple <tamara@tamaratemple.com>
- * @param array $options_array - array of options (return value => option string),
- * @param string $element_name - name and id of the select statement
- * @param string $label=null - label to be used for select statement
- * @param string $selected_item=null - key in $options_array to be preselected
- **/
- function dynamic_select ($options_array,
- $element_name,
- $label=null,
- $selected_item=null)
- {
- $out = PHP_EOL;
- if (!empty($label)) $out .= "<label for \"$element_name\">$label</label>".PHP_EOL;
- $out .= "<select name=\"$element_name\" id=\"$element_name\">".PHP_EOL;
- foreach ($options_array as $key => $value) {
- $out .= " <option value=\"$key\"";
- if ($key == $selected_item) $out .= " selected=\"selected\"";
- $out .= ">$value</option>".PHP_EOL;
- }
- $out .= "</select>".PHP_EOL;
- return $out;
- } // END function dynamic_select
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement