Пример #1
0
 public function edit($id = '')
 {
     /***********************************
     		Edit form
     		************************************/
     $this->f3->scrub($_POST);
     $cards = new Cards($this->db);
     $this->f3->set('deck', $cards->read(array('id=?', $id), [])[0]);
     $this->f3->set('SESSION.flash', array());
     if ($this->f3->exists('POST.edit')) {
         // validate form
         if (!preg_match("/^[\\w\\-]{2,30}\$/", $this->f3->get('POST.filename'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid name. Only letters, numbers, underscores (_), and dashes (-) are allowed.'));
         }
         // if there are no errors, process the form
         if (count($this->f3->get('SESSION.flash')) === 0) {
             if ($cards->edit($id)) {
                 $this->f3->push('SESSION.flash', array('type' => 'success', 'msg' => 'Deck ' . $this->f3->get('POST.filename') . ' edited!'));
                 $this->f3->reroute('/mytcg/cards');
             } else {
                 $this->f3->push('SESSION.flash', array('type' => 'danger', 'msg' => 'There was a problem processing your request. Please try again!'));
             }
         }
     }
     $this->f3->set('content', 'app/views/mytcg/cards_edit.htm');
     echo Template::instance()->render('app/templates/admin.htm');
 }