Jump to content

Archived

This topic is now archived and is closed to further replies.

ionik

Zend_Form Validation

Recommended Posts

Any Zend_Form Junkies have quite a difficult question

 

Question Is as follows.

 

I have created my own custom extension onto Zend_Form and took the whole process down into one single method to create elements add the decorators everything. The problem that I am having is when I add a validator to a element such as

 

$element->addValidator(new Validator_Username($nameList));

 

my validation is as follows within a constructor

$this->form->addUser();

	if(!$this->_getParam('submit') || !$this->form->isValid($_POST))
        {
            $this->view->addContent = $this->form->render();

		// Set View AScript Path
		$this->view->addScriptPath(ADMIN_PAGE_TEMPLATES.'users');

		$this->view->adminContent = $this->admin->renderViewLeft( $this->view->render('add.phtml') );

 

I am trying to do the validation all in on single class method and not have to write it out for each and every element when the form is submitted ( If i did this there is 500 form elements I'd need to this for and we'll I don't have 2 months to do that )

 

the code to add the validator is simple

 

$element->addPrefixPath('Validator', 'Validator/', 'validate');

        switch($validater)
        {
            case 'username':
                $element->addValidator(new Validator_Username(array('Admin')));
                $element->setRequired(true);
                break;
            case 'email':
                $element->addValidator(new Zend_Validate_EmailAddress());
                $element->setRequired(true);
            break;

            case 'password':
                $element->addValidators(array(
                                              array('validator' => 'NotEmpty'),
                                              array('stringLength', false, array(4, 20))
                                              ));
                $element->setRequired(true);
                break;
            case 'confirm':
                $element->addValidator(new Validator_Password_Confirm());
                break;

        }

 

that is called within my _createElement() and the element is created etc etc etc...

 

create element method is as follows

protected function _createElement($name, $label, $type, $value = null, $desc = null, $options = null, $attrib = null, $validater = null) {}
//Example
$username = $this->_createElement('username', 'Username', 'text', '', 'You must enter a alphanumeric username that is between 4-15 characters', '', '', 'username');

 

Validation will work for Zend_Validate_EmailAddress but will not return any error messages for me, and I have the error helpers setup in the decorators...

 

Anyone have any idea how to get this working??

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.