PMA\libraries\Util::getRadioFields PHP Method

getRadioFields() public static method

Generates a set of radio HTML fields
public static getRadioFields ( string $html_field_name, array $choices, string $checked_choice = '', boolean $line_break = true, boolean $escape_label = true, string $class = '', string $id_prefix = '' ) : string
$html_field_name string the radio HTML field
$choices array the choices values and labels
$checked_choice string the choice to check by default
$line_break boolean whether to add HTML line break after a choice
$escape_label boolean whether to use htmlspecialchars() on label
$class string enclose each choice with a div of this class
$id_prefix string prefix for the id attribute, name will be used if this is not supplied
return string set of html radio fiels
    public static function getRadioFields($html_field_name, $choices, $checked_choice = '', $line_break = true, $escape_label = true, $class = '', $id_prefix = '')
    {
        $radio_html = '';
        foreach ($choices as $choice_value => $choice_label) {
            if (!empty($class)) {
                $radio_html .= '<div class="' . $class . '">';
            }
            if (!$id_prefix) {
                $id_prefix = $html_field_name;
            }
            $html_field_id = $id_prefix . '_' . $choice_value;
            $radio_html .= '<input type="radio" name="' . $html_field_name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
            if ($choice_value == $checked_choice) {
                $radio_html .= ' checked="checked"';
            }
            $radio_html .= ' />' . "\n" . '<label for="' . $html_field_id . '">' . ($escape_label ? htmlspecialchars($choice_label) : $choice_label) . '</label>';
            if ($line_break) {
                $radio_html .= '<br />';
            }
            if (!empty($class)) {
                $radio_html .= '</div>';
            }
            $radio_html .= "\n";
        }
        return $radio_html;
    }

Usage Example

/**
 * Get HTML snippet for partition maintenance
 *
 * @param array $partition_names array of partition names for a specific db/table
 * @param array $url_params      url parameters
 *
 * @return string $html_output
 */
function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
{
    $choices = array('ANALYZE' => __('Analyze'), 'CHECK' => __('Check'), 'OPTIMIZE' => __('Optimize'), 'REBUILD' => __('Rebuild'), 'REPAIR' => __('Repair'), 'TRUNCATE' => __('Truncate'));
    $partition_method = Partition::getPartitionMethod($GLOBALS['db'], $GLOBALS['table']);
    // add COALESCE or DROP option to choices array depeding on Partition method
    if ($partition_method == 'RANGE' || $partition_method == 'LIST') {
        $choices['DROP'] = __('Drop');
    } else {
        $choices['COALESCE'] = __('Coalesce');
    }
    $html_output = '<div class="operations_half_width">' . '<form id="partitionsForm" class="ajax" ' . 'method="post" action="tbl_operations.php" >' . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']) . '<fieldset>' . '<legend>' . __('Partition maintenance') . PMA\libraries\Util::showMySQLDocu('partitioning_maintenance') . '</legend>';
    $html_select = '<select id="partition_name" name="partition_name[]"' . ' multiple="multiple" required="required">' . "\n";
    $first = true;
    foreach ($partition_names as $one_partition) {
        $one_partition = htmlspecialchars($one_partition);
        $html_select .= '<option value="' . $one_partition . '"';
        if ($first) {
            $html_select .= ' selected="selected"';
            $first = false;
        }
        $html_select .= '>' . $one_partition . '</option>' . "\n";
    }
    $html_select .= '</select>' . "\n";
    $html_output .= sprintf(__('Partition %s'), $html_select);
    $html_output .= '<div class="clearfloat" />';
    $html_output .= PMA\libraries\Util::getRadioFields('partition_operation', $choices, 'ANALYZE', false, true, 'floatleft');
    $this_url_params = array_merge($url_params, array('sql_query' => 'ALTER TABLE ' . PMA\libraries\Util::backquote($GLOBALS['table']) . ' REMOVE PARTITIONING;'));
    $html_output .= '<div class="clearfloat" /><br />';
    $html_output .= '<a href="sql.php' . PMA_URL_getCommon($this_url_params) . '">' . __('Remove partitioning') . '</a>';
    $html_output .= '</fieldset>' . '<fieldset class="tblFooters">' . '<input type="hidden" name="submit_partition" value="1">' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</form>' . '</div>';
    return $html_output;
}
All Usage Examples Of PMA\libraries\Util::getRadioFields
Util