Hi, I'm just wondering if someone can help me. I have a registration form
like so which doesn't seem to wnt to work:

<?php
namespace Auth\Form;

use Zend\Form\Form;
use Zend\Form\Element;

class RegForm extends Form
{
    public function __construct($name = null)
    {
        // we want to ignore the name passed
        parent::__construct('register');
        $this->setAttribute('method', 'post');
                $this->add(array(
                        'type' => 'text',
            'name' => 'title',
            'options' => array(
                'label' => 'Title',
            ),
        ));
                $this->add(array(
                        'type' => 'text',
            'name' => 'firstName',
            'options' => array(
                'label' => 'First Name',
            ),
        ));
                $this->add(array(
                        'type' => 'text',
            'name' => 'surname',
            'options' => array(
                'label' => 'Surname',
            ),
        ));
                $this->add(array(
                        'type' => 'text',
            'name' => 'address1',
            'options' => array(
                'label' => 'Address 1',
            ),
        ));
                $this->add(array(
                        'type' => 'text',
            'name' => 'address2',
            'options' => array(
                'label' => 'Address 2',
            ),
        ));
                $this->add(array(
                        'type' => 'text',
            'name' => 'townCity',
            'options' => array(
                'label' => 'Town/City',
            ),
        ));
                $this->add(array(
                        'type' => 'text',
            'name' => 'postCode',
            'options' => array(
                'label' => 'Post Code',
            ),
        ));
                $this->add(array(
            'name' => 'phone',
            'options' => array(
                'label' => 'Telephone',
            ),
                        'attributes' => array(
                     'type' => 'tel',
             ),
        ));
        $this->add(array(
                        'type' => 'Zend\Form\Element\Email',
            'name' => 'regEmail',
            'options' => array(
                'label' => 'Email Address',
            ),
        ));
                $this->add(array(
            'name' => 'password',
            'attributes' => array(
                'type'  => 'password',
            ),
            'options' => array(
                'label' => 'Password',
            ),
        ));
        $this->add(array(
            'name' => 'passwordRepeat',
            'attributes' => array(
                'type'  => 'password',
            ),
            'options' => array(
                'label' => 'Repeat Password',
            ),
        ));
        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Register',
                'id' => 'btnRegister',
            ),
        ));
    }
}

The form has an input filter within its own standalone class called
RegInputFilter:

<?php 
namespace Auth\Entity;

use Zend\InputFilter\Factory as InputFactory;
use Auth\Model\Customer;   
use Zend\InputFilter\InputFilter;                 
use Zend\InputFilter\InputFilterAwareInterface;  
use Zend\InputFilter\InputFilterInterface;
use Zend\Validator\Db;

class RegInputFilter extends InputFilter 
{ 
        protected $adapter;
        
    public function __construct() 
    { 
                $this->add($this->getFactory()->createInput(array(
                'name'     => 'title',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                                        array(
                                                'name' => 'StringLength',
                                                'options' => array(
                                                        'max' => 5
                                                ),
                                        ),
                ),
            )));
                        $this->add($this->getFactory()->createInput(array(
                'name'     => 'firstName',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                                        array(
                                                'name' => 'StringLength',
                                                'options' => array(
                                                        'max' => 25
                                                ),
                                        ),
                ),
            )));
                        $this->add($this->getFactory()->createInput(array(
                'name'     => 'surname',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                                        array(
                                                'name' => 'StringLength',
                                                'options' => array(
                                                        'max' => 25
                                                ),
                                        ),
                ),
            )));
                        $this->add($this->getFactory()->createInput(array(
                'name'     => 'address1',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                                        array(
                                                'name' => 'StringLength',
                                                'options' => array(
                                                        'max' => 30
                                                ),
                                        ),
                ),
            )));
                        $this->add($this->getFactory()->createInput(array(
                'name'     => 'address2',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                                        array(
                                                'name' => 'StringLength',
                                                'options' => array(
                                                        'max' => 30
                                                ),
                                        ),
                ),
            )));
                        $this->add($this->getFactory()->createInput(array(
                'name'     => 'townCity',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                                        array(
                                                'name' => 'StringLength',
                                                'options' => array(
                                                        'max' => 30
                                                ),
                                        ),
                ),
            )));
                        $this->add($this->getFactory()->createInput(array(
                'name'     => 'postCode',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                                        array(
                                                'name' => 'StringLength',
                                                'options' => array(
                                                        'max' => 12
                                                ),
                                        ),
                ),
            )));
                        $this->add($this->getFactory()->createInput(array(
                'name'     => 'phone',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                                        array('name' => 'StringTrim'),
                ),
                'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
                ),
            )));
                        
        $this->add($this->getFactory()->createInput(array( 
            'name'     => 'regEmail', 
            'required' => true, 
            'filters'  => array( 
                array('name' => 'StripTags'), 
                array('name' => 'StringTrim'), 
            ), 
            'validators' => array( 
                array( 
                    'name'    => 'EmailAddress', 
                    'options' => array( 
                    ), 
                ), 
            ), 
        ))); 
                
                $this->add($this->getFactory()->createInput(array( 
            'name'     => 'email', 
            'required' => true, 
            'filters'  => array( 
                array('name' => 'StripTags'), 
                array('name' => 'StringTrim'), 
            ), 
            'validators' => array( 
                array( 
                    'name'    => 'EmailAddress', 
                    'options' => array( 
                    ), 
                ), 
            ), 
        ))); 
                
                $this->add($this->getFactory()->createInput(array( 
            'name'     => 'password', 
            'required' => true, 
            'filters'  => array( 
                array('name' => 'StripTags'), 
            ), 
            'validators' => array(
                                        array(
                                                'name' => 'NotEmpty',
                                        ),
            ),
        ))); 
                
                $this->add($this->getFactory()->createInput(array( 
            'name'     => 'passwordRepeat', 
            'required' => true, 
            'filters'  => array( 
                array('name' => 'StripTags'), 
            ), 
            'validators' => array( 
                                array(
                                        'name' => 'Identical',
                                        'options' => array(
                                                'token' => 'password', // name 
of first password field
                                        ),
                                ), 
                                array(
                                                'name' => 'NotEmpty',
                                ),
            ), 
        ))); 
                
    } 
} 

and I use this form within the registerAction in the AuthController for all
registering of users:

        public function registerAction()
        {
                $form = new RegForm();
                $inputFilter = new RegInputFilter();
                
                $request = $this->getRequest();
        if ($request->isPost()) {
                        $cust = new Customer();
                        
                        $form->setInputFilter($inputFilter);
                        $form->setData($request->getPost());
                        
                        if ($form->isValid()) {
                $cust->exchangeArray($form->getData());
                $this->getCustomerTable()->registerCustomer($cust);

                // Redirect to list of albums
                return $this->redirect()->toRoute('auth\register');
            }
                        else {
                                var_dump($form->getMessages());
                        }
                }               
                return array('form' => $form);
        }

I've check using var_dump on the form->getMessages() method, however all
that is returned is an empty array.

I'd appreciate if somebody could help out a noob. I've been stuck for 2
hours on this little error haha

Kind Regards,
Jamie



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Zend-form-isValid-returns-false-and-empty-array-is-returned-tp4659626.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to