protected function _init() { if ($this->id) { $sth = $this->dbh->prepare('SELECT * FROM form WHERE id=?'); $sth->setFetchMode(PDO::FETCH_INTO, $this); $sth->execute(array($this->id)); if (!$sth->fetch()) { die('huhh?'); } } elseif ($this->slug) { $sth = $this->dbh->prepare('SELECT * FROM form WHERE slug=?'); $sth->setFetchMode(PDO::FETCH_INTO, $this); $sth->execute(array($this->slug)); if (!$sth->fetch()) { die('huh?'); } } // custom fields for this form $sth = $this->dbh->prepare('SELECT * FROM field WHERE form_id=? ORDER BY sort_order,slug'); $sth->setFetchMode(PDO::FETCH_ASSOC); $sth->execute(array($this->id)); while ($row = $sth->fetch()) { $this->fields[] = Field::from_database($this->dbh, $row); } // standard notes field $f = new Field(); $f->slug = 'note'; $f->label = 'Note'; $this->fields[] = $f; }