示例#1
0
 /**
  * Get form rules for a field.
  */
 public static function get_rules($field)
 {
     $rules = array();
     // skip auto-incrementing fields
     if (DBMan::is_auto_incrementing($field)) {
         return $rules;
     }
     if ($field->notnull == 'No') {
         $rules['not empty'] = 1;
     }
     if (in_array($field->type, array('int', 'integer', 'float'))) {
         $rules['type'] = 'numeric';
     }
     if ($field->length != '') {
         $rules['length'] = $field->length . '-';
     }
     return $rules;
 }
示例#2
0
        return;
    }
    $this->add_notification(i18n_get('Item updated.'));
    $this->redirect('/dbman/browse?table=' . $_GET['table']);
}
// get the initial object from the database
$o = db_single(sprintf('select * from `%s` where %s = ?', $_GET['table'], DBMan::primary_key($_GET['table'])), $_GET['key']);
// generate the form
$o = $f->merge_values($o);
$o->failed = $f->failed;
echo "<form method='post'>\n";
$timepicker_loaded = false;
// generate the form fields
foreach ($fields as $field) {
    // disable auto-incrementing fields
    if (DBMan::is_auto_incrementing($field)) {
        printf('<input type="hidden" name="%s" value="%s" />' . "\n", $field->name, $o->{$field->name});
        continue;
    }
    if (isset($f->rules[$field->name]['type']) && $f->rules[$field->name]['type'] == 'numeric') {
        $rule = ' <span class="notice" id="' . $field->name . '-notice">' . i18n_getf('You must enter a number for %s', $field->name) . '</span>';
    } elseif (isset($f->rules[$field->name]['length'])) {
        $rule = ' <span class="notice" id="' . $field->name . '-notice">' . i18n_getf('You must enter a value for %s no longer than %s', $field->name, $field->length) . '</span>';
    } elseif (isset($f->rules[$field->name]['not empty'])) {
        $rule = ' <span class="notice" id="' . $field->name . '-notice">' . i18n_getf('You must enter a value for %s', $field->name) . '</span>';
    } else {
        $rule = '';
    }
    switch ($field->type) {
        case 'text':
            printf('<p>%s:<br /><textarea name="%s" cols="60" rows="8">%s</textarea>%s</p>' . "\n", $field->name, $field->name, Template::quotes($o->{$field->name}), $rule);