zend form check record no exists in database

Posted by Yafa Su on Stack Overflow See other posts from Stack Overflow or by Yafa Su
Published on 2012-12-18T20:58:36Z Indexed on 2012/12/19 11:03 UTC
Read the original article Hit count: 154

Filed under:
|
|
|

I have a form that check if email exists in the database within 2 tables.

I'm using Zend_Validate_Db_NoRecordExists for both validate, but it only check the second one.

Any idea why it's not working?

class Application_Form_ReferUser extends Zend_Form
{
public $email, $freeDownload, $buyNow;

public function init()
{
    $this->setName('referUser');

    $EmailExists = new Zend_Validate_Db_NoRecordExists(
        array(
            'table' => 'referrals',
            'field' => 'email'
        )
    );

    $EmailExists2 = new Zend_Validate_Db_NoRecordExists(
        array(
            'table' => 'users',
            'field' => 'email'
        )
    );

    $EmailExists->setMessage('This e-mail is already taken');
    $EmailExists2->setMessage('This e-mail is already taken');

    $this->email = $this->createElement('text', 'email')
                     ->setLabel('Email')
                     ->addValidator($EmailExists)
                     ->addValidator($EmailExists2)
                     ->addValidator('EmailAddress')
                     ->setRequired(true);

    $this->freeDownload = $this->createElement('button', 'btn_free_download')
                            ->setLabel('Free Download')
                            ->setAttrib('type', 'submit');

    $this->buyNow = $this->createElement('button', 'btn_buy_now')
                            ->setLabel('Buy Now')
                            ->setAttrib('type', 'submit');

    $this->addElements(array($this->email, $this->freeDownload, $this->buyNow));

    $elementDecorators = array(
        'ViewHelper'
    );
    $this->setElementDecorators($elementDecorators);
}
}

© Stack Overflow or respective owner

Related posts about php

Related posts about database