src/UI/CrudForm.php
public static function insertForm($fields, $from_location, $titles=false) {
        echo('<form method="post">'."\n");

        for($i=0; $i < count($fields); $i++ ) {
            $field = $fields[$i];

            // Don't allow setting of these fields
            if ( strpos($field, "_at") > 0 ) continue;
            if ( strpos($field, "_sha256") > 0 ) continue;

            echo('<div class="form-group">'."\n");
            echo('<label for="'.$field.'">'.self::fieldToTitle($field, $titles)."<br/>\n");

            if ( strpos($field, "secret") !== false ) {
                echo('<input id="'.$field.'" type="password" autocomplete="off" size="80" name="'.$field.'"');
                echo("onclick=\"if ( $(this).attr('type') == 'text' ) $(this).attr('type','password'); else $(this).attr('type','text'); return false;\">\n");
            } else {
                echo('<input type="text" size="80" id="'.$field.'" name="'.$field.'">'."\n");
            }
            echo("</label>\n</div>");
        }

        echo('<input type="submit" name="doSave" class="btn btn-normal" value="'._m("Save").'">'."\n");
        echo('<a href="'.$from_location.'" class="btn btn-default">Cancel</a>'."\n");
        echo('</form>'."\n");
    }
public static function insertForm($fields, $from_location, $titles=false) {
        echo('<form method="post">'."\n");

        for($i=0; $i < count($fields); $i++ ) {
            $field = $fields[$i];

            // Don't allow setting of these fields
            if ( strpos($field, "_at") > 0 ) continue;
            if ( strpos($field, "_sha256") > 0 ) continue;

            echo('<div class="form-group">'."\n");
            echo('<label for="'.$field.'">'.self::fieldToTitle($field, $titles)."<br/>\n");

            if ( strpos($field, "secret") !== false ) {
                echo('<input id="'.$field.'" type="password" autocomplete="off" size="80" name="'.$field.'"');
                echo("onclick=\"if ( $(this).attr('type') == 'text' ) $(this).attr('type','password'); else $(this).attr('type','text'); return false;\">\n");
            } else {
                echo('<input type="text" size="80" id="'.$field.'" name="'.$field.'">'."\n");
            }
            echo("</label>\n</div>");
        }

        echo('<input type="submit" name="doSave" class="btn btn-normal" value="'._m("Save").'">'."\n");
        echo('<a href="'.$from_location.'" class="btn btn-default">Cancel</a>'."\n");
        echo('</form>'."\n");
    }
public static function insertForm ( $ fields , $ from_location , $ titles = false ) { echo ( '<form method="post">' . "\n" ) ; for ( $ i = 0 ; $ i < count ( $ fields ) ; $ i ++ ) { $ field = $ fields [ $ i ] ; // Don't allow setting of these fields if ( strpos ( $ field , "_at" ) > 0 ) continue ; if ( strpos ( $ field , "_sha256" ) > 0 ) continue ; echo ( '<div class="form-group">' . "\n" ) ; echo ( '<label for="' . $ field . '">' . self :: fieldToTitle ( $ field , $ titles ) . "<br/>\n" ) ; if ( strpos ( $ field , "secret" ) !== false ) { echo ( '<input id="' . $ field . '" type="password" autocomplete="off" size="80" name="' . $ field . '"' ) ; echo ( "onclick=\"if ( $(this).attr('type') == 'text' ) $(this).attr('type','password'); else $(this).attr('type','text'); return false;\">\n" ) ; } else { echo ( '<input type="text" size="80" id="' . $ field . '" name="' . $ field . '">' . "\n" ) ; } echo ( "</label>\n</div>" ) ; } echo ( '<input type="submit" name="doSave" class="btn btn-normal" value="' . _m ( "Save" ) . '">' . "\n" ) ; echo ( '<a href="' . $ from_location . '" class="btn btn-default">Cancel</a>' . "\n" ) ; echo ( '</form>' . "\n" ) ; }
Generate the HTML for an insert form.

Here is a sample call:

$from_location = "keys.php";
$fields = array("key_key", "key_sha256", "secret", "created_at", "updated_at");
CrudForm::insertForm($fields, $from_location);

@param $fields An array of fields to prompt for.
@param $from_location A URL to jump to when the user presses 'Cancel'.
@param $titles An array of fields->titles
Generate the HTML for an insert form .