src/HtmlGenerator.php
/**
     * Generates the html for a button which runs the provided javascript 
     * functionName when clicked. This is a button element e.g. <button> and 
     * NOT an input type='button'. There are subtle differences, but the main 
     * one is that the text for a button is NOT changed by changingt the .value 
     * but the .textContent attribute, and input type buttons are supposed
     * to be inside a form and will submit data with the form. Both can have an 
     * onclick.
     * 
     * @param string label        - text user can see on the button
     * @param string functionName - name of javascript function to call when the
     *                              button is clicked.
     * @param array parameters    - parameters to pass to the js function.
     * @param bool confirm        - whether the user needs to confirm that they 
     *                              meant to click the button.
     * @param string confMessage  - if confirm set to true, the confirmation 
     *                              message as it will appear.
     * 
     * @return stringString - the html for the button.
     */
Generates the html for a button which runs the provided javascript
functionName when clicked. This is a button element e.g.  and
NOT an input type='button'. There are subtle differences, but the main
one is that the text for a button is NOT changed by changingt the .value
but the .textContent attribute, and input type buttons are supposed
to be inside a form and will submit data with the form. Both can have an
onclick.

@param string label        - text user can see on the button
@param string functionName - name of javascript function to call when the
button is clicked.
@param array parameters    - parameters to pass to the js function.
@param bool confirm        - whether the user needs to confirm that they
meant to click the button.
@param string confMessage  - if confirm set to true, the confirmation
message as it will appear.

@return stringString - the html for the button.
Generates the html for a button which runs the provided javascript functionName when clicked . This is a button element e . g . and NOT an input type = ' button ' . There are subtle differences but the main one is that the text for a button is NOT changed by changingt the . value but the . textContent attribute and input type buttons are supposed to be inside a form and will submit data with the form . Both can have an onclick . @param string label - text user can see on the button @param string functionName - name of javascript function to call when the button is clicked . @param array parameters - parameters to pass to the js function . @param bool confirm - whether the user needs to confirm that they meant to click the button . @param string confMessage - if confirm set to true the confirmation message as it will appear . @return stringString - the html for the button .
public static function generateButton($label, 
                                          $functionName, 
                                          $parameters  = array(), 
                                          $confirm     = false, 
                                          $confMessage = "")
    {
        $parameterString = "";
        if (count($parameters) > 0)
        {
            foreach ($parameters as $parameter)
            {
                $literals = array('this', 'true', 'false');
                $lowerCaseParam = strtolower($parameter);
                if (in_array($lowerCaseParam, $literals))
                {
                    $parameterString .= $parameter . ", ";
                }
                else
                {
                    $parameterString .= "'" . $parameter . "', ";
                }
            } 
            $parameterString = substr($parameterString, 0, -2);
        }
        $onclick = $functionName . "(" . $parameterString . ")";
        if ($confirm)
        {
            $onclick = "if (confirm('" . $confMessage . "')){" . $onclick . "}";
        }
        $onclick = '"' . $onclick . '"';
        $htmlString = '<button onclick=' . $onclick . '>' . 
                          $label . 
                      '</button>';
        return $htmlString;
    }
public static function generateButton ( $ label , $ functionName , $ parameters = array ( ) , $ confirm = false , $ confMessage = " " ) { $ parameterString = " " ; if ( count ( $ parameters ) > 0 ) { foreach ( $ parameters as $ parameter ) { $ literals = array ( 'this' , 'true' , 'false' ) ; $ lowerCaseParam = strtolower ( $ parameter ) ; if ( in_array ( $ lowerCaseParam , $ literals ) ) { $ parameterString .= $ parameter . " ,  " ; } else { $ parameterString .= " ' " . $ parameter . " ',  " ; } } $ parameterString = substr ( $ parameterString , 0 , - 2 ) ; } $ onclick = $ functionName . " ( " . $ parameterString . " ) " ; if ( $ confirm ) { $ onclick = " if (confirm(' " . $ confMessage . " ')){ " . $ onclick . " } " ; } $ onclick = '"' . $ onclick . '"' ; $ htmlString = '<button onclick=' . $ onclick . '>' . $ label . '</button>' ; return $ htmlString ; }
Generates the html for a button which runs the provided javascript
 functionName when clicked.
Generates the html for a button which runs the provided javascript functionName when clicked .
# Handle cases where we want to pass `this`, 'true' or 'false'. // Remove the last character which should be an excess ,