开发者

Not all fields are being saved in my MySQL Database

My form class:

<?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')
             开发者_JS百科       ->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'));
    }
}
?>

And here I'm saving things:

<?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);          
        //}     
    }
}

?>

And here's a screenshot of how things are being saved:

Not all fields are being saved in my MySQL Database

What am I doing wrong? Not even the dates I write are being saved.

Here's the table structure:

Not all fields are being saved in my MySQL Database


You are not setting the POST'ed values to the Form.

Either uncomment the line with

$form->isValid($_POST)

or call

$form->populate($_POST)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜