Dovrei convalidare dei campi.
Nel senso che se si inserisce qualcosa di sbagliato su di un campo deve poi comparire un messaggiodi errore del tipo email inserita non valita. Avrei pensato a Zend_Validator, anche se ho guardato la guida, non ho capito il funzionamento.
Ho questo codice nel file authcontroller
codice:
<?php
class AuthController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
$form = new Application_Form_Login();
$request = $this->getRequest();
if ($request->isPost())
{
if ($form->isValid($request->getPost()))
{
if (Zend_Validate_EmailAddress::INVALID_FORMAT('email'))
{
echo 'email non iserita correttamente';
}
/* if ($this->_process($form->getValues('password')))
{
$this->_helper->redirector('index', 'index');
}*/
}
}
$this->view->form = $form;
}
protected function _process($values)
{
$adapter=$this->_getAuthAdapter();
$adapter->setIdentity($values['username']);
$adapter->setCredential($values['password']);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if ($result->isValid())
{
$user =$adapter->getResultRowObject();
$auth->getStorage()->write($user);
return true;
}
return false;
}
protected function _getAuthAdapter()
{
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('utenti')
->setIdentityColumn('username')
->setCredentialColumn('password');
return $authAdapter;
}
public function registrationAction()
{
// action body
$form = new Application_Form_Login();
$form->submit->setLabel('Registration');
$this->view->form = $form;
if ($this->getRequest()->isPost())
{
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData))
{
$nome = $form->getValue('nome');
$cognome = $form->getValue('cognome');
$username = $form->getValue('username');
$password = $form->getValue('password');
$email = $form->getValue('email');
$ruolo = $form->getValue('ruolo');
$login= new Application_Model_DbTable_Utenti();
$login->updateUtenti($id, $nome, $cognome, $username, $password, $email, $ruolo);
$this->_helper->redirector('index');
}
else
{ $form->populate($formData); }
}
else
{
$id = $this->_getParam('id', 0);
if ($id > 0)
{
$utenti = new Application_Model_DbTable_Utenti();
$form->populate($utenti->getUtenti($id));
}
}
}
}
e questo nel file login.phph nella form
codice:
$this->addElement('text','nome', array(
'filters'=>array('StringTrim','StringToLower'),
'messaqes'=>'Non valido'
'validators'=>array(
array('StringLength', false, array(0, 50)),),
'required'=>true,
'label'=>'email',));