public static function selectField( $name, $options, $attributes, $value = null, $fieldProperties = null, $ID = null )
    {
        if( empty( $name ) ) {
            return false;
        }

        if( empty( $options ) ) {
            trigger_error("Object <strong>{$name}</strong> has no valid options!", E_USER_WARNING);
            return false;
        }

        $fieldProperties   = empty( $fieldProperties ) ? array() : ( is_array($fieldProperties) ? $fieldProperties : array( $fieldProperties ) );
        $baseAttributes    = array( 'ID' => $name, 'name' => $name );
        $source            = '';
        $hasSelectedOption = false;

        foreach( $options as $item ) {
            $option         = '';
            $selectedOption = '';

            if( !$hasSelectedOption && ( isset( $item['selected'] ) || ( $item == $value ) || ( isset( $item['value'] ) && $value == $item['value'] ) ) ) {
                $selectedOption    = 'selected="selected"';
                $hasSelectedOption = true;
            }

            if( !is_array($item) ) {
                $option .= "<option {$selectedOption} value=\"{$item}\">{$item}</option>";
            } else {
                $option = "<option ";
                if( isset( $item['value'] ) ) {
                    $option .= " value=\"{$item['value']}\" {$selectedOption}";
                } else {
                    $option .= " value=\"{$item['text']}\" {$selectedOption}";
                }

                $option = trim($option) . ">{$item['text']}</option>";
            }
            $source .= $option;
        }

        $attsString = self::arrayToHTMLAttributes(array_merge($baseAttributes, $attributes));
        $output     = "<select {$attsString}>{$source}</select>";

        $field             = new \stdClass();
        $field->html       = $output;
        $field->properties = array_merge($baseAttributes, $attributes, array( 'options' => $options ), $fieldProperties);

        return $field;
    }
public static function selectField( $name, $options, $attributes, $value = null, $fieldProperties = null, $ID = null )
    {
        if( empty( $name ) ) {
            return false;
        }

        if( empty( $options ) ) {
            trigger_error("Object <strong>{$name}</strong> has no valid options!", E_USER_WARNING);
            return false;
        }

        $fieldProperties   = empty( $fieldProperties ) ? array() : ( is_array($fieldProperties) ? $fieldProperties : array( $fieldProperties ) );
        $baseAttributes    = array( 'ID' => $name, 'name' => $name );
        $source            = '';
        $hasSelectedOption = false;

        foreach( $options as $item ) {
            $option         = '';
            $selectedOption = '';

            if( !$hasSelectedOption && ( isset( $item['selected'] ) || ( $item == $value ) || ( isset( $item['value'] ) && $value == $item['value'] ) ) ) {
                $selectedOption    = 'selected="selected"';
                $hasSelectedOption = true;
            }

            if( !is_array($item) ) {
                $option .= "<option {$selectedOption} value=\"{$item}\">{$item}</option>";
            } else {
                $option = "<option ";
                if( isset( $item['value'] ) ) {
                    $option .= " value=\"{$item['value']}\" {$selectedOption}";
                } else {
                    $option .= " value=\"{$item['text']}\" {$selectedOption}";
                }

                $option = trim($option) . ">{$item['text']}</option>";
            }
            $source .= $option;
        }

        $attsString = self::arrayToHTMLAttributes(array_merge($baseAttributes, $attributes));
        $output     = "<select {$attsString}>{$source}</select>";

        $field             = new \stdClass();
        $field->html       = $output;
        $field->properties = array_merge($baseAttributes, $attributes, array( 'options' => $options ), $fieldProperties);

        return $field;
    }
public static function selectField ( $ name , $ options , $ attributes , $ value = null , $ fieldProperties = null , $ ID = null ) { if ( empty ( $ name ) ) { return false ; } if ( empty ( $ options ) ) { trigger_error ( "Object <strong>{$name}</strong> has no valid options!" , E_USER_WARNING ) ; return false ; } $ fieldProperties = empty ( $ fieldProperties ) ? array ( ) : ( is_array ( $ fieldProperties ) ? $ fieldProperties : array ( $ fieldProperties ) ) ; $ baseAttributes = array ( 'ID' => $ name , 'name' => $ name ) ; $ source = '' ; $ hasSelectedOption = false ; foreach ( $ options as $ item ) { $ option = '' ; $ selectedOption = '' ; if ( ! $ hasSelectedOption && ( isset ( $ item [ 'selected' ] ) || ( $ item == $ value ) || ( isset ( $ item [ 'value' ] ) && $ value == $ item [ 'value' ] ) ) ) { $ selectedOption = 'selected="selected"' ; $ hasSelectedOption = true ; } if ( ! is_array ( $ item ) ) { $ option .= "<option {$selectedOption} value=\"{$item}\">{$item}</option>" ; } else { $ option = "<option " ; if ( isset ( $ item [ 'value' ] ) ) { $ option .= " value=\"{$item['value']}\" {$selectedOption}" ; } else { $ option .= " value=\"{$item['text']}\" {$selectedOption}" ; } $ option = trim ( $ option ) . ">{$item['text']}</option>" ; } $ source .= $ option ; } $ attsString = self :: arrayToHTMLAttributes ( array_merge ( $ baseAttributes , $ attributes ) ) ; $ output = "<select {$attsString}>{$source}</select>" ; $ field = new \ stdClass ( ) ; $ field -> html = $ output ; $ field -> properties = array_merge ( $ baseAttributes , $ attributes , array ( 'options' => $ options ) , $ fieldProperties ) ; return $ field ; }
Generate a Select Field.
@param $name
@param $options : An array with items. Accepts simple array or nested array with the properties [text, value, selected]
@param $attributes
@return bool|string
Generate a Select Field .