Example #1
0
 public function save()
 {
     $params = parent::ifIsset($this, array('label', 'term', 'expires_at'));
     if (isset($this->id)) {
         return parent::edit('blocks', $this->id, $params, 'firewall_store');
     }
     $this->id = parent::put('blocks', $params, 'firewall_store');
     return $this->id;
 }
Example #2
0
File: Form.php Project: Alm001/form
 /**
  * Override the `put()` method to validate structures before
  * saving them.
  */
 public function put()
 {
     if (!$this->_validate_fields($this->field_list)) {
         $this->error = 'Fields failed to validate';
         return false;
     }
     if (!$this->_validate_actions($this->actions)) {
         $this->error = 'Actions failed to validate';
         return false;
     }
     return parent::put();
 }
Example #3
0
 /**
  * Need to verify extended fields, so we override the put() method.
  */
 public function put()
 {
     $f = new Form();
     $failed = $f->verify_values($this->ext(), $this->_extended_verify);
     if (!empty($failed)) {
         $this->error = 'Validation failed for extended fields: ' . join(', ', $failed);
         return false;
     }
     return parent::put();
 }
Example #4
0
File: Post.php Project: eksith/Blog
 public function save()
 {
     $params = parent::ifIsset($this, array('title', 'summary', 'raw', 'plain', 'body', 'slug', 'published_at', 'status'));
     if (isset($this->id)) {
         return parent::edit('posts', $this->id, $params);
     }
     $params['parent_id'] = $this->parent_id;
     $params['user_id'] = $this->user_id;
     $this->id = parent::put('posts', $params);
     return $this->id;
 }
Example #5
0
 /**
  * Need to verify extended fields, so we override the `put()` method.
  * Note: On update forms, call `update_extended()` if the fields were
  * set by the `admin/util/extended` handler.
  */
 public function put()
 {
     $failed = Validator::validate_list($this->ext(), $this->_extended_verify);
     if (!empty($failed)) {
         $this->error = 'Validation failed for extended fields: ' . join(', ', $failed);
         return false;
     }
     return parent::put();
 }
Example #6
0
$page->layout = 'admin';
$page->title = i18n_get('Add') . ' ' . $_GET['table'];
// get the field details of the table so we can dynamically generate the form
$fields = DBMan::table_info($_GET['table']);
$f = new Form('post');
$f->verify_csrf = false;
// generate rules for required fields
foreach ($fields as $field) {
    $f->rules[$field->name] = DBMan::get_rules($field);
}
if ($f->submit()) {
    // add item
    $obj = new Model($_POST);
    $obj->table = $_GET['table'];
    $obj->key = DBMan::primary_key($_GET['table']);
    if ($obj->put()) {
        $this->add_notification(i18n_get('Item added.'));
        $this->redirect('/dbman/browse?table=' . $_GET['table']);
    }
    $page->title = i18n_get('An Error Occurred');
    printf("<p>%s</p>\n<p><a href='/dbman/browse?table=%s'>&laquo; %s</a></p>\n", $obj->error, $_GET['table'], i18n_get('Back'));
    return;
}
// generate the form
$o = new StdClass();
// set default values
foreach ($fields as $field) {
    if (!empty($field->default)) {
        $o->{$field->name} = $field->default;
    }
}