html_state_select

1.0 1.1 1.2 1.3

Returns a simple HTML select element filled with a list of all US States.

<?php
html_state_select(string $name, [ string $width = "100%", [int $size = false, [bool $multiselect = false]]] )
  • name: The name and id of the select element
  • width: The vertical display size of the select element, defaults to false
  • size: moo, defaults to foo
  • multiselect: A flag signifing multiple selections, defaults to false

Examples

Example #1

index.tpl
{html_state_select name="state" width="200px"}

The above example will output:

<select name="state" id="state" style="width:200px;">
 <option value="AL">Alabama</option>
 ...
 <option value="WY">Wyoming</option>
</select>

Example #2

index.tpl
{html_state_select name="state" size="5" multiselect="true"}

The above example will output:

<select name="state" id="state" style="width:100%;" size="5" multiple="multiple">
 <option value="AL">Alabama</option>
 ...
 <option value="WY">Wyoming</option>
</select>

Sources

Dwoo_Plugin_html_state_select.php
<?php
/**
 * {html_state_select} is a custom function that creates an html <select> containing a list of all US States 
 * 
 * <pre>
 *  * name: The name and id of the selection box
 *  * width: The width of the select box as used in a style attribute
 *  * size: the vertical display size of the select element
 *  * multiselect: A flag signifing multiple selections
 * </pre>
 * 
 * 
 * - All output is XHTML compliant. 
 * 
 * 
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * This file is released under the LGPL
 * "GNU Lesser General Public License"
 * More information can be found here:
 * {@link http://www.gnu.org/copyleft/lesser.html}
 *
 * @author     James Murray <http://www.vertigolabs.org>
 * @copyright  Copyright (c) 2008, James Murray
 * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
 * @link       http://dwoo.org/
 * @date       2009-04-09
 * @package    Dwoo
 */
class Dwoo_Plugin_html_state_select extends Dwoo_Plugin
{
	public function process($name, $width="100%", $size=false, $multiselect=false) {
 
		$return  = '<select name="'.$name.'" id="'.$name.'" style="width:'.$width.';"';
		if ($size != false && is_numeric($size)) {
			$return .= ' size="'.$size.'"';
		}
		if ($multiselect == true) {
			$return .= ' multiple="multiple"';
		}
		$return .='>';
 
		$return .='			<option value="" selected="selected">State</option> 
			<option value="AL">Alabama</option> 
			<option value="AK">Alaska</option> 
			<option value="AZ">Arizona</option> 
			<option value="AR">Arkansas</option> 
			<option value="CA">California</option> 
			<option value="CO">Colorado</option> 
			<option value="CT">Connecticut</option> 
			<option value="DE">Delaware</option> 
			<option value="DC">District Of Columbia</option> 
			<option value="FL">Florida</option> 
			<option value="GA">Georgia</option> 
			<option value="HI">Hawaii</option> 
			<option value="ID">Idaho</option> 
			<option value="IL">Illinois</option> 
			<option value="IN">Indiana</option> 
			<option value="IA">Iowa</option> 
			<option value="KS">Kansas</option> 
			<option value="KY">Kentucky</option> 
			<option value="LA">Louisiana</option> 
			<option value="ME">Maine</option> 
			<option value="MD">Maryland</option> 
			<option value="MA">Massachusetts</option> 
			<option value="MI">Michigan</option> 
			<option value="MN">Minnesota</option> 
			<option value="MS">Mississippi</option> 
			<option value="MO">Missouri</option> 
			<option value="MT">Montana</option> 
			<option value="NE">Nebraska</option> 
			<option value="NV">Nevada</option> 
			<option value="NH">New Hampshire</option> 
			<option value="NJ">New Jersey</option> 
			<option value="NM">New Mexico</option> 
			<option value="NY">New York</option> 
			<option value="NC">North Carolina</option> 
			<option value="ND">North Dakota</option> 
			<option value="OH">Ohio</option> 
			<option value="OK">Oklahoma</option> 
			<option value="OR">Oregon</option> 
			<option value="PA">Pennsylvania</option> 
			<option value="RI">Rhode Island</option> 
			<option value="SC">South Carolina</option> 
			<option value="SD">South Dakota</option> 
			<option value="TN">Tennessee</option> 
			<option value="TX">Texas</option> 
			<option value="UT">Utah</option> 
			<option value="VT">Vermont</option> 
			<option value="VA">Virginia</option> 
			<option value="WA">Washington</option> 
			<option value="WV">West Virginia</option> 
			<option value="WI">Wisconsin</option> 
			<option value="WY">Wyoming</option>
		</select>';
		return $return;
	}
}