php - Zend Form Input Element -
it's form class:
<?php class application_form_message extends zend_form { public function init() { $this->setmethod('post'); $this->addelement( 'text', 'email', array( 'label' => 'e-mail', 'filters' => array('stringtrim'), 'class' => 'size-large-big', 'required' => true ) ); $this->addelement( 'text', 'subject', array( 'label' => 'subject', 'filters' => array('stringtrim'), 'class' => 'size-large-big', 'required' => true ) ); $this->addelement( 'textarea', 'content', array( 'label' => 'content', 'filters' => array('stringtrim'), 'class' => 'size-large-big', 'required' => true ) ); $this->addelement( 'file', 'file', array( 'label' => 'attachments', 'filters' => array('stringtrim'), 'class' => 'size-large-big', 'isarray' => true, 'required' => false, 'allowempty' => true, 'style' => 'display: inline;' ) ); $this->file->setdestination(realpath(application_path . '/../public/uploads')) ->addvalidator('extension', false, 'png, jpg, jpeg', 'pdf', 'doc', 'docx'); $this->file->getvalidator('upload')->setmessages(array( zend_validate_file_upload::no_file => 'empty filename', )); $this->addelement( 'submit', 'submit', array( 'ignore' => true, 'label' => 'send', 'class' => 'btn' ) ); } }
my view:
<div class="container" > <section class="main"> <form action="<?php echo $this->form->getaction(); ?>" method="<?php echo $this->form->getmethod(); ?>"> <ul class="form-inputs login"> <h2>message</h2> <p><?php echo $this->page->content; ?></p> <li> <?php echo $this->form->email->renderlabel(); ?> <?php echo $this->form->email->renderviewhelper(); ?> </li> <li> <?php echo $this->form->subject->renderlabel(); ?> <?php echo $this->form->subject->renderviewhelper(); ?> </li> <li> <?php echo $this->form->content->renderlabel(); ?> <?php echo $this->form->content->renderviewhelper(); ?> </li> <li> <?php echo $this->form->file->renderlabel(); ?> <?php echo $this->form->file->renderfile(); ?> </li> <li> <?php echo $this->form->submit->renderviewhelper(); ?> </li> </ul> </form> </section> </div>
the problem form isn't valid, if fill inputs , add 1 file.
print_r($form->getmessages()); //error messages print_r($form->geterrors()); //error codes print_r($form->geterrormessages()); //any custom error messages
controller:
public function newaction() { $page = new application_model_dbtable_page(); $form = new application_form_message(); if($this->getrequest()->ispost()) { if ($form->isvalid($this->getrequest()->getpost())) { $data = $form->getvalues(); die('its ok'); $this->_sendcomplaint($data['subject'], $data['content'], $data['email']); } else { print_r($form->getmessages()); //error messages print_r($form->geterrors()); //error codes print_r($form->geterrormessages()); //any custom error messages } } else $form->email->setvalue($this->view->userdetails->email); $this->view->page = $page->getpagebyslug('message'); $this->view->form = $form; $this->view->pagename = 'message'; }
return me nothing, empty arrays: array ( ) array ( [email] => array ( ) [subject] => array ( ) [content] => array ( ) [file] => array ( ) [submit] => array ( ) ) array ( )
thanks help.
i found problem myself, enctype="multipart/form-data"
attribute missing in form tag.
Comments
Post a Comment