Jump to content

Zend_Form Validation


ionik

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??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.