baser/views/helpers/form_ex.php
/**
 * Returns a formatted SELECT element.
 * Attributes:
 *
 * - 'showParents' - If included in the array and set to true, an additional option element
 *   will be added for the parent of each option group.
 * - 'multiple' - show a multiple select box.  If set to 'checkbox' multiple checkboxes will be
 *   created instead.
 *
 * @param string $fieldName Name attribute of the SELECT
 * @param array $options Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the
 *    SELECT element
 * @param mixed $selected The option selected by default.  If null, the default value
 *   from POST data will be used when available.
 * @param array $attributes The HTML attributes of the select element.
 * @param mixed $showEmpty If true, the empty select option is shown.  If a string,
 *   that string is displayed as the empty element.
 * @return string Formatted SELECT element
 * @access public
 */
Returns a formatted SELECT element.
Attributes.

- 'showParents' - If included in the array and set to true, an additional option element
will be added for the parent of each option group.
- 'multiple' - show a multiple select box.  If set to 'checkbox' multiple checkboxes will be
created instead.

@param string $fieldName Name attribute of the SELECT
@param array $options Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the
SELECT element
@param mixed $selected The option selected by default.  If null, the default value
from POST data will be used when available.
@param array $attributes The HTML attributes of the select element.
@param mixed $showEmpty If true, the empty select option is shown.  If a string,
that string is displayed as the empty element.
@return string Formatted SELECT element
@access public
Returns a formatted SELECT element . Attributes . - ' showParents ' - If included in the array and set to true an additional option element will be added for the parent of each option group . - ' multiple ' - show a multiple select box . If set to ' checkbox ' multiple checkboxes will be created instead . @param string $fieldName Name attribute of the SELECT @param array $options Array of the OPTION elements ( as ' value ' = > ' Text ' pairs ) to be used in the SELECT element @param mixed $selected The option selected by default . If null the default value from POST data will be used when available . @param array $attributes The HTML attributes of the select element . @param mixed $showEmpty If true the empty select option is shown . If a string that string is displayed as the empty element . @return string Formatted SELECT element @access public
function select($fieldName, $options = array(), $selected = null, $attributes = array(), $showEmpty = '') {
		$select = array();
		$showParents = false;
		$escapeOptions = true;
		$style = null;
		$tag = null;
		if (isset($attributes['escape'])) {
			$escapeOptions = $attributes['escape'];
			unset($attributes['escape']);
		}
		$attributes = $this->_initInputField($fieldName, array_merge(
			(array)$attributes, array('secure' => false)
		));
		if (is_string($options) && isset($this->__options[$options])) {
			$options = $this->__generateOptions($options);
		} elseif (!is_array($options)) {
			$options = array();
		}
		if (isset($attributes['type'])) {
			unset($attributes['type']);
		}
		if (in_array('showParents', $attributes)) {
			$showParents = true;
			unset($attributes['showParents']);
		}
		if (!isset($selected)) {
			$selected = $attributes['value'];
		}
		if (isset($attributes) && array_key_exists('multiple', $attributes)) {
			$style = ($attributes['multiple'] === 'checkbox') ? 'checkbox' : null;
			$template = ($style) ? 'checkboxmultiplestart' : 'selectmultiplestart';
			$tag = $this->Html->tags[$template];
			if(!isset($attributes['hidden']) || $attributes['hidden']!==false) {
				$select[] = $this->hidden(null, array('value' => '', 'id' => null, 'secure' => false));
			}
		} else {
			$tag = $this->Html->tags['selectstart'];
		}
		if (!empty($tag) || isset($template)) {
			$this->__secure();
			$select[] = sprintf($tag, $attributes['name'], $this->_parseAttributes(
				$attributes, array('name', 'value'))
			);
		}
		$emptyMulti = (
			$showEmpty !== null && $showEmpty !== false && !(
				empty($showEmpty) && (isset($attributes) &&
				array_key_exists('multiple', $attributes))
			)
		);
		if ($emptyMulti) {
			$showEmpty = ($showEmpty === true) ? '' : $showEmpty;
			$options = array_reverse($options, true);
			$options[''] = $showEmpty;
			$options = array_reverse($options, true);
		}
		if(isset($attributes['div'])) {
			if($attributes['div']=='false') {
				$attributes['div'] = false;
			}
			$div = $attributes['div'];
		}else {
			$div = null;
		}
		$_select = $this->__selectOptions(
			array_reverse($options, true),
			$selected,
			array(),
			$showParents,
			array('escape' => $escapeOptions, 'style' => $style, 'div' => $div)
		);
		if(!empty($attributes['separator'])) {
			$separator = $attributes['separator']."\n";
		}else {
			$separator = "\n";
		}
		$select[] = implode($separator, $_select);
		$template = ($style == 'checkbox') ? 'checkboxmultipleend' : 'selectend';
		$select[] = $this->Html->tags[$template];
		if(isset($attributes['multiple']) && $attributes['multiple'] === true) {
			list($model,$field) = explode(".",$fieldName);
			$tagName = Inflector::camelize($model . '_' . $field);
			$out = '<script type="text/javascript">';
			$out .= "jQuery(document).ready(function() {";
			$out .= "jQuery('#".$tagName."Clear').click(function(){";
			$out .= "jQuery('#".$tagName."').val('');";
			$out .= "});";
			$out .= "});";
			$out .= "</script>";
			$out .= '<input type="button" name="'.$tagName.'Clear" id="'.$tagName.'Clear" value="　解　除　" />';
			return $this->output(implode("\n", $select))."<br />".$out;
		}else {
			return $this->output(implode("\n", $select));
		}
	}
function select ( $ fieldName , $ options = array ( ) , $ selected = null , $ attributes = array ( ) , $ showEmpty = '' ) { $ select = array ( ) ; $ showParents = false ; $ escapeOptions = true ; $ style = null ; $ tag = null ; if ( isset ( $ attributes [ 'escape' ] ) ) { $ escapeOptions = $ attributes [ 'escape' ] ; unset ( $ attributes [ 'escape' ] ) ; } $ attributes = $ this -> _initInputField ( $ fieldName , array_merge ( ( array ) $ attributes , array ( 'secure' => false ) ) ) ; if ( is_string ( $ options ) && isset ( $ this -> __options [ $ options ] ) ) { $ options = $ this -> __generateOptions ( $ options ) ; } elseif ( ! is_array ( $ options ) ) { $ options = array ( ) ; } if ( isset ( $ attributes [ 'type' ] ) ) { unset ( $ attributes [ 'type' ] ) ; } if ( in_array ( 'showParents' , $ attributes ) ) { $ showParents = true ; unset ( $ attributes [ 'showParents' ] ) ; } if ( ! isset ( $ selected ) ) { $ selected = $ attributes [ 'value' ] ; } if ( isset ( $ attributes ) && array_key_exists ( 'multiple' , $ attributes ) ) { $ style = ( $ attributes [ 'multiple' ] === 'checkbox' ) ? 'checkbox' : null ; $ template = ( $ style ) ? 'checkboxmultiplestart' : 'selectmultiplestart' ; $ tag = $ this -> Html -> tags [ $ template ] ; if ( ! isset ( $ attributes [ 'hidden' ] ) || $ attributes [ 'hidden' ] !== false ) { $ select [ ] = $ this -> hidden ( null , array ( 'value' => '' , 'id' => null , 'secure' => false ) ) ; } } else { $ tag = $ this -> Html -> tags [ 'selectstart' ] ; } if ( ! empty ( $ tag ) || isset ( $ template ) ) { $ this -> __secure ( ) ; $ select [ ] = sprintf ( $ tag , $ attributes [ 'name' ] , $ this -> _parseAttributes ( $ attributes , array ( 'name' , 'value' ) ) ) ; } $ emptyMulti = ( $ showEmpty !== null && $ showEmpty !== false && ! ( empty ( $ showEmpty ) && ( isset ( $ attributes ) && array_key_exists ( 'multiple' , $ attributes ) ) ) ) ; if ( $ emptyMulti ) { $ showEmpty = ( $ showEmpty === true ) ? '' : $ showEmpty ; $ options = array_reverse ( $ options , true ) ; $ options [ '' ] = $ showEmpty ; $ options = array_reverse ( $ options , true ) ; } if ( isset ( $ attributes [ 'div' ] ) ) { if ( $ attributes [ 'div' ] == 'false' ) { $ attributes [ 'div' ] = false ; } $ div = $ attributes [ 'div' ] ; } else { $ div = null ; } $ _select = $ this -> __selectOptions ( array_reverse ( $ options , true ) , $ selected , array ( ) , $ showParents , array ( 'escape' => $ escapeOptions , 'style' => $ style , 'div' => $ div ) ) ; if ( ! empty ( $ attributes [ 'separator' ] ) ) { $ separator = $ attributes [ 'separator' ] . " \n " ; } else { $ separator = " \n " ; } $ select [ ] = implode ( $ separator , $ _select ) ; $ template = ( $ style == 'checkbox' ) ? 'checkboxmultipleend' : 'selectend' ; $ select [ ] = $ this -> Html -> tags [ $ template ] ; if ( isset ( $ attributes [ 'multiple' ] ) && $ attributes [ 'multiple' ] === true ) { list ( $ model , $ field ) = explode ( " . " , $ fieldName ) ; $ tagName = Inflector :: camelize ( $ model . '_' . $ field ) ; $ out = '<script type="text/javascript">' ; $ out .= " jQuery(document).ready(function() { " ; $ out .= " jQuery('# " . $ tagName . " Clear').click(function(){ " ; $ out .= " jQuery('# " . $ tagName . " ').val(''); " ; $ out .= " }); " ; $ out .= " }); " ; $ out .= " </script> " ; $ out .= '<input type="button" name="' . $ tagName . 'Clear" id="' . $ tagName . 'Clear" value="　解　除　" />'; return $ this -> output ( implode ( " \n " , $ select ) ) . " <br /> " . $ out ; } else { return $ this -> output ( implode ( " \n " , $ select ) ) ; } }
Returns a formatted SELECT element.
Returns a formatted SELECT element .
// >>> CUSTOMIZE MODIFY 2011/01/21 ryuring // multiplecheckboxの場合にhiddenをつけないオプションを追加 //$select[] = $this->hidden(null, array('value' => '', 'id' => null, 'secure' => false)); // --- // <<< // divを追加すぐ下の__selectOptionsのみで利用 // 解除ボタンを追加（jQuery必須)