我的表单类:
<?php
require_once ('Zend\Form.php');
class Sergio_Form_registrationform extends Zend_Form {
public function init(){
/*********************USERNAME**********************/
$username = new Zend_Form_Element_Text('username');
$alnumValidator = new Zend_Validate_Alnum();
$username ->setRequired(true)
->setLabel('Username:')
->addFilter('StringToLower')
->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength',false,array(6,20));
$this->addElement($username);
/*********************EMAIL**********************/
$email = new Zend_Form_Element_Text('email');
$alnumValidator = new Zend_Validate_Alnum();
$email ->setRequired(true)
->setLabel('EMail:')
->addFilter('StringToLower')
->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength',false,array(6,20));
$this->addElement($email);
/*********************PASSWORD**********************/
$password = new Zend_Form_Element_Password('password');
$alnumValidator = new Zend_Validate_Alnum();
$password ->setRequired(true)
->setLabel('Password:')
->addFilter('StringToLower')
->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength',false,array(6,20));
$this->addElement($password);
/*********************NAME**********************/
$name = new Zend_Form_Element_Text('name');
$alnumValidator = new Zend_Validate_Alnum();
$name ->setRequired(true)
->setLabel('Name:')
->addFilter('StringToLower')
->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength',false,array(6,20));
$this->addElement($name);
/*********************LASTNAME**********************/
$lastname = new Zend_Form_Element_Text('lastname');
$alnumValidator = new Zend_Validate_Alnum();
$lastname ->setRequired(true)
->setLabel('Last Name:')
->addFilter('StringToLower')
->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength',false,array(6,20));
$this->addElement($lastname);
/*********************DATEOFBIRTH**********************/
$dateofbirth = new Zend_Form_Element_Text('dateofbirth');
$alnumValidator = new Zend_Validate_Alnum();
$dateofbirth->setRequired(true)
->setLabel('Date of Birth:')
->addFilter('StringToLower')
->addValidator('alnum')
->addValidator('regex', false, array('/^[a-z]+/'))
->addValidator('stringLength',false,array(6,20));
$this->addElement($dateofbirth);
/*********************AVATAR**********************/
$avatar = new Zend_Form_Element_File('avatar');
$alnumValidator = new Zend_Validate_Alnum();
$avatar ->setRequired(true)
->setLabel('Please select a display picture:');
$this->addElement($avatar);
/*********************SUBMIT**********************/
$this->addElement('submit', 'login', array('label' => 'Login'));
}
}
?>
我在这里拯救了一切:
<?php
require_once ('Zend\Controller\Action.php');
class RegistrationController extends Zend_Controller_Action {
//For each of these methods, you MUST have another phtml file in the respective View folder.
public function indexAction(){
$form = new Sergio_Form_registrationform();
$this->view->form = $form;
}
public function init(){
$this->_setParam('db',Zend_Db_Table_Abstract::getDefaultAdapter());
}
public function saveforminformationAction(){
$form = new Sergio_Form_registrationform();
$request = $this->getRequest();
//if($request->isPost() && $form->isValid($_POST)){
$data = $form->getValues();
unset($data['login']);
$db = $this->_getParam('db');
$db->insert('user',$data);
//}
}
}
?>
以下是有关如何保存事物的截图:
我做错了什么?甚至我写的日期都没有保存。
这是表结构:
答案 0 :(得分:0)
您没有将POST的值设置为表单。
使用
取消注释该行$form->isValid($_POST)
或致电
$form->populate($_POST)