src/HtmlGenerator.php
/**
     * Generates an html drop down menu for forms. If the array of drop down options passed in is
     * an array, then the value posted will be the key, and the display label for the option will be
     * the value.
     *
     * @param name           - name to assign to the input field (the lookup name when retrieving 
     *                          POST)
     * @param currentValue   - the current/default/selected value of that attribute.
     * @param options        - array of all the possible options/values that the user can pick
     *                          if this is an associative array, the key will be used as the value.
     * @param rowSize        - manually set the number of rows to show
     * @param multipleSelect - optional - set true if user should be able to select multiple values.
     * @param onChange       - specify javascript that should run when the dropdown changes. Note 
     *                          that this should not contain the text onchange= and if quotes are 
     *                          used (for js function parameters, then these should be encapsulated
     *                          in double quotes.
     * @param id             - (optional) set an id for the dropdown menu.
     *
     * @return stringString - the generated html to be put on the page.
     */
Generates an html drop down menu for forms. If the array of drop down options passed in is
an array, then the value posted will be the key, and the display label for the option will be
the value.

@param name           - name to assign to the input field (the lookup name when retrieving
POST)
@param currentValue   - the current/default/selected value of that attribute.
@param options        - array of all the possible options/values that the user can pick
if this is an associative array, the key will be used as the value.
@param rowSize        - manually set the number of rows to show
@param multipleSelect - optional - set true if user should be able to select multiple values.
@param onChange       - specify javascript that should run when the dropdown changes. Note
that this should not contain the text onchange= and if quotes are
used (for js function parameters, then these should be encapsulated
in double quotes.
@param id             - (optional) set an id for the dropdown menu.

@return stringString - the generated html to be put on the page.
Generates an html drop down menu for forms . If the array of drop down options passed in is an array then the value posted will be the key and the display label for the option will be the value . @param name - name to assign to the input field ( the lookup name when retrieving POST ) @param currentValue - the current / default / selected value of that attribute . @param options - array of all the possible options / values that the user can pick if this is an associative array the key will be used as the value . @param rowSize - manually set the number of rows to show @param multipleSelect - optional - set true if user should be able to select multiple values . @param onChange - specify javascript that should run when the dropdown changes . Note that this should not contain the text onchange = and if quotes are used ( for js function parameters then these should be encapsulated in double quotes . @param id - ( optional ) set an id for the dropdown menu . @return stringString - the generated html to be put on the page .
public static function generateDropDownMenu($name, 
                                                $currentValue, 
                                                $options, 
                                                $rowSize        = 1,
                                                $multipleSelect = false,
                                                $onChange       = "", 
                                                $id             = "")
    {
        $isAssoc = self::isAssoc($options);
        $optionsHtml = "";
        foreach ($options as $key => $option)
        {   
            $optionValue = $option;
            $optionLabel = $option;
            if ($isAssoc)
            {
                $optionValue = $key;
            }
            $selectedAttribute = "";
            if ($optionValue == $currentValue)
            {
                $selectedAttribute = " selected='true' ";
            }
            $optionsHtml .= "<option " . $selectedAttribute . 
                                'value="' . $optionValue . '"' .
                            ">" . 
                                $optionLabel . 
                            "</option>" . PHP_EOL;
        }
        $nameAttribute      = " name='" . $name . "' ";
        $idAttribute = "";
        if ($id != "")
        {
            $idAttribute = " id='" . $name . "' ";
        }
        $sizeAttribute      = " size='" . $rowSize . "' ";
        $onChangeAttribute  = "";
        if ($onChange != "")
        {
            $onChangeAttribute = " onchange='" . $onChange . "' ";
        }
        $multipleAttribute  = "";
        if ($multipleSelect)
        {   
            $multipleAttribute = " multiple ";
        }
        $htmlString = 
            "<select" .
                $idAttribute . 
                $nameAttribute . 
                $sizeAttribute . 
                $onChangeAttribute . 
                $multipleAttribute . 
            ">" . 
                $optionsHtml . 
            "</select>";
        return $htmlString;
    }
public static function generateDropDownMenu ( $ name , $ currentValue , $ options , $ rowSize = 1 , $ multipleSelect = false , $ onChange = " " , $ id = " " ) { $ isAssoc = self :: isAssoc ( $ options ) ; $ optionsHtml = " " ; foreach ( $ options as $ key => $ option ) { $ optionValue = $ option ; $ optionLabel = $ option ; if ( $ isAssoc ) { $ optionValue = $ key ; } $ selectedAttribute = " " ; if ( $ optionValue == $ currentValue ) { $ selectedAttribute = "  selected='true'  " ; } $ optionsHtml .= " <option  " . $ selectedAttribute . 'value="' . $ optionValue . '"' . " > " . $ optionLabel . " </option> " . PHP_EOL ; } $ nameAttribute = "  name=' " . $ name . " '  " ; $ idAttribute = " " ; if ( $ id != " " ) { $ idAttribute = "  id=' " . $ name . " '  " ; } $ sizeAttribute = "  size=' " . $ rowSize . " '  " ; $ onChangeAttribute = " " ; if ( $ onChange != " " ) { $ onChangeAttribute = "  onchange=' " . $ onChange . " '  " ; } $ multipleAttribute = " " ; if ( $ multipleSelect ) { $ multipleAttribute = "  multiple  " ; } $ htmlString = " <select " . $ idAttribute . $ nameAttribute . $ sizeAttribute . $ onChangeAttribute . $ multipleAttribute . " > " . $ optionsHtml . " </select> " ; return $ htmlString ; }
Generates an html drop down menu for forms.
Generates an html drop down menu for forms .