examples/build-form.php
/**
 * Converts info response to HTML input
 * Notice! This is a bare-bone function, it doesn't wrap generated input or display help or anything
 * It just builds input
 *
 * @param string $name
 * @param array  $field
 *
 * @return string
 */
Converts info response to HTML input
Notice. This is a bare-bone function, it doesn't wrap generated input or display help or anything
It just builds input

@param string $name
@param array  $field

@return string
Converts info response to HTML input Notice . This is a bare - bone function it doesn ' t wrap generated input or display help or anything It just builds input @param string $name @param array $field @return string
function fieldToHtml($name, array $field)
{
    $html = '<input type="#TYPE#" name="#NAME#"#REQUIRED##READONLY##CLASSNAME##TITLE#>';
    $r = array(
        '#TYPE#'      => in_array($field['class'], array('String_Email', 'Text_Email'), true) ? 'email' : 'text',
        '#NAME#'      => $name,
        '#REQUIRED#'  => empty($field['is_required']) ? '' : ' required',
        '#READONLY#'  => empty($field['is_readonly']) ? '' : ' readonly',
        '#CLASSNAME#' => empty($field['classname']) ? '' : ' class="' . $field['classname'] . '"',
        '#TITLE#'     => empty($field['title']) ? ' placeholder="' . $name . '"' : ' title="' . $field['title'] . '" placeholder="' . $field['title'] . '"',
    );
    if (strpos($field['class'], 'String_Textarea') === 0 || strpos($field['class'], 'Text_Textarea') === 0) {
        $html = '<textarea name="#NAME#"#REQUIRED##READONLY##CLASSNAME##TITLE#></textarea>';
    } elseif (in_array($field['class'], array('String_Nameserver', 'Text_Nameserver'), true)) {
        $html = '<input type="#TYPE#" name="#NAME#[host]"#REQUIRED##READONLY##CLASSNAME##TITLE#>';
    } elseif (strpos($field['class'], 'Checkbox') === 0) {
        $html = '<label><input type="checkbox" value="1"#REQUIRED##READONLY##CLASSNAME#>' . (!empty($field['title']) ? $field['title'] : $name) . '</label>';
    } elseif (strpos($field['class'], 'Select') === 0) {
        $html = '<select name="#NAME#"#REQUIRED##READONLY##CLASSNAME##TITLE#>#OPTIONS#</select>';
        $r['#OPTIONS#'] = '<option value="">Select...</option>';
        foreach ($field['select_options'] as $optionName => $optionValue) {
            $r['#OPTIONS#'] .= '<option value="'. $optionName .'">' . $optionValue . '</option>';
        }
    }
    $html = str_replace(array_keys($r), array_values($r), $html);
    return $html;
}
function fieldToHtml ( $ name , array $ field ) { $ html = '<input type="#TYPE#" name="#NAME#"#REQUIRED##READONLY##CLASSNAME##TITLE#>' ; $ r = array ( '#TYPE#' => in_array ( $ field [ 'class' ] , array ( 'String_Email' , 'Text_Email' ) , true ) ? 'email' : 'text' , '#NAME#' => $ name , '#REQUIRED#' => empty ( $ field [ 'is_required' ] ) ? '' : ' required' , '#READONLY#' => empty ( $ field [ 'is_readonly' ] ) ? '' : ' readonly' , '#CLASSNAME#' => empty ( $ field [ 'classname' ] ) ? '' : ' class="' . $ field [ 'classname' ] . '"' , '#TITLE#' => empty ( $ field [ 'title' ] ) ? ' placeholder="' . $ name . '"' : ' title="' . $ field [ 'title' ] . '" placeholder="' . $ field [ 'title' ] . '"' , ) ; if ( strpos ( $ field [ 'class' ] , 'String_Textarea' ) === 0 || strpos ( $ field [ 'class' ] , 'Text_Textarea' ) === 0 ) { $ html = '<textarea name="#NAME#"#REQUIRED##READONLY##CLASSNAME##TITLE#></textarea>' ; } elseif ( in_array ( $ field [ 'class' ] , array ( 'String_Nameserver' , 'Text_Nameserver' ) , true ) ) { $ html = '<input type="#TYPE#" name="#NAME#[host]"#REQUIRED##READONLY##CLASSNAME##TITLE#>' ; } elseif ( strpos ( $ field [ 'class' ] , 'Checkbox' ) === 0 ) { $ html = '<label><input type="checkbox" value="1"#REQUIRED##READONLY##CLASSNAME#>' . ( ! empty ( $ field [ 'title' ] ) ? $ field [ 'title' ] : $ name ) . '</label>' ; } elseif ( strpos ( $ field [ 'class' ] , 'Select' ) === 0 ) { $ html = '<select name="#NAME#"#REQUIRED##READONLY##CLASSNAME##TITLE#>#OPTIONS#</select>' ; $ r [ '#OPTIONS#' ] = '<option value="">Select...</option>' ; foreach ( $ field [ 'select_options' ] as $ optionName => $ optionValue ) { $ r [ '#OPTIONS#' ] .= '<option value="' . $ optionName . '">' . $ optionValue . '</option>' ; } } $ html = str_replace ( array_keys ( $ r ) , array_values ( $ r ) , $ html ) ; return $ html ; }
Converts info response to HTML input
 Notice!
Converts info response to HTML input Notice!