Temat: Zend form w osobnym bloku (sidebar)?
To moze tak po caloscie:
Formularz:
class Application_Form_Login extends Zend_Form
{
public function init()
{
// Set the method for the display form to POST
$this->setMethod('post');
$this->setAction('/auth/');
// Add an email element
$email = $this->addElement('text', 'email', array(
'label' => 'Email:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress')
));
Zend_Debug::dump($email);
// Add a login element
$password = $this->addElement('password', 'password', array(
'label' => 'Password:',
'required' => true,
'filters' => array('StringTrim')
));
// Add the submit button
$submit = $this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Login',
));
// And finally add some CSRF protection
$hash = $this->addElement('hash', 'csrf', array(
'ignore' => true,
));
}
}
Helper:
class App_View_Helpers_LoginForm extends Zend_View_Helper_Abstract
{
public $view;
public function loginForm()
{
return new Application_Form_Login();
}
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
}}
Layout:
echo $this->loginForm();
Controller:
class AuthController extends App_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$request = $this->getRequest();
$form = new Application_Form_Login();
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
return $this->_helper->redirector('index');
}
}
$this->view->form = $form;
}
}
Zend_Debug nie zwraca mi zadnej z podanych przez ciebie metod.
Marceli Podstawski edytował(a) ten post dnia 17.02.12 o godzinie 16:28