namespace Application\Form; use Zend\Form\Form; class ContactForm extends Form { public function __construct() { parent::__construct(); $this->setAttribute('method', 'post'); $this->setAttribute('action', ''); 'name' => 'name', 'required' => true, 'type' => 'Text', 'label' => 'Name', ), )); 'name' => 'email', 'required' => true, 'type' => 'Text', 'label' => 'Email', ), )); 'name' => 'text', 'required' => true, 'type' => 'Textarea', 'label' => 'Text', ), )); 'name' => 'submit', 'type' => 'Submit', 'value' => 'Go', 'id' => 'submitbutton', ), )); } }
w controllerze przekazuje go do widoku
$form = new ContactForm();
I to działa wszystko. Rozchodzi mi się o funkcję isValid. Mam przykładowo:
i nie wypełniając żadnego pola to tak daje wynik: ok
public function indexAction() { $request = $this->getRequest(); $form = new ContactForm(); $data = $request->getPost(); $form->setData($data); if($form->isValid()) { $data = $form->getData(); return new ViewModel($array); }
+ prosze wytłumaczcie mi o co chodzi z funkcja $form->getData skoro i tak pokazują aby pobierac dane z klasy request? ($this->getRequest()->getPost());
ktoś pomoże?
@up
