/ Published in: PHP
I wrote this little bit of code myself so if you see where you can improve on it, let me know. This is great for making complex menu's and also for making sure your POST data gets saved and reselected when the screen refreshes. I use it in all my programs now, makes menu generation a snap.
In order to use this you need to make sure you set at minimum
$menu_vars as an array of values and $menu_postvalue as a string to the be the name of the POST field. By default, if no $menu_values is set, $menu_vars will be set both to be the display and value.
Example Usage in the Snippet
I look forward to your feedback.
In order to use this you need to make sure you set at minimum
$menu_vars as an array of values and $menu_postvalue as a string to the be the name of the POST field. By default, if no $menu_values is set, $menu_vars will be set both to be the display and value.
Example Usage in the Snippet
I look forward to your feedback.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function menu_generator($menu_vars="",$menu_postvalue="",$menu_values="", $blank=true, $selected="", $class="") { if($selected) { $selector=$selected; } else { $selector=$_POST[$menu_postvalue]; } if(!$menu_values) { $menu_values=$menu_vars; } else { $menu_values=$menu_values; } echo "<select name=\"$menu_postvalue\" $class >"; if($blank) { echo "<option value=\"\"></option>"; } { $value=$menu_generate[$i]; $value2=$menu_generate2[$i]; if($value2 == $selector) { echo "<option value=\"$value2\" selected=\"selected\">$value</option>"; } else { echo "<OPTION value=\"$value2\">$value</option>"; } } echo "</select>"; } $menu_postvalue = "Numbers"; menu_generator($menu_vars, $menu_postvalue);