$form → addSubmit (‚send‘,‚ulozit clanok‘); nic nevykona
- chiquitin
- Člen | 9
<?php
namespace App\Presenters ;
use Nette;
use Nette\Application\UI\Form;
Class PostPresenter extends Nette\Application\UI\Presenter{
private $database;
public function __construct(Nette\Database\Context $database){
$this->database = $database;
}
public function renderShow (int $postId):void
{
$post =$this->database->table('posts')->get($postId);
if(!$post)
$this->error('stranka sa nenasla');
$this->template->post=$post;
$this->template->post = $post;
$this->template->comments = $post->related('comment')->order('created_at');
}
protected function createComponentCommentForm(): Form
{ $form = new Form;
$form -> addText('name','Meno')
-> setRequired();
$form -> addEmail('email','Email');
$form -> addTextArea('content','Komentar')
-> setRequired();
$form -> addSubmit ('send','Publikovat komentar');
$form->onSuccess[] = [$this,'commentFormSucceeded'];
return $form;
}
public function commentFormSucceeded(Form $form, \stdClass $values): void
{
$postId = $this->getParameter('postId');
$this->database->table('comments')->insert([
'post_id' => $postId,
'name' => $values->name,
'email' => $values->email,
'content' => $values->content
]);
$this->flashMessage('dakujjem za komentar', 'success');
$this->redirect('this');
}
protected function createComponentPostForm(): Form
{
$form=new Form;
$form-> addText ('title','Titulok')
->setRequired();
$form -> addText ('content','Obsah')
->setRequired();
$form -> addSubmit ('send','ulozit clanok');
$form->onSuccess[] = [$this, 'postFormSucceeded'];
return $form;
}
public function postFormSucceeded ( Form $form, \stdClass $values) :void
{
$post= $this->database->table('posts')->insert([
'title' => $values->title,
'content' => $values->content]);
$this->flashMessage('Publikovane.', 'success');
$this->redirect('show',$post->id);
}
}
Zdravim $form → addSubmit (‚send‘,‚ulozit clanok‘); vyzera ze nic nerobi. nevyhadzuje ani ziadny error. Formular na pridavanie sa mi zobrazi a zj ho vyplnim len po kliku na "ulozit clanok sa nic nestane. Dakujem za rady
- Ondřej Kubíček
- Člen | 494
nic se nestane jakože se form z prohlížeče ani neodešleš? nebo odešle ale na serveru se nic nestane? v prvním případě zkontroluj jestli javascriptem neodchytáváš submit, ve druhém se to debugni a podívej se kde co se stane…