Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:23:40+00:00 2026-06-11T10:23:40+00:00

I am working on a project based on Zend framework. In user registration I

  • 0

I am working on a project based on Zend framework. In user registration I have to check for unique email. My code is working fine when I register a user for the first time, but when I try to update the user information and press the update button, it gives the error message:

Email already taken 

Please help me to solve this problem. My code is attached below:

$this->addElement('text', 'email', array(
                'label'      => 'Your email address:',
                'required'   => true,
                'filters'    => array('StringTrim'),
                'validators' => array(
                        'EmailAddress',
                        array('Db_NoRecordExists', true, array(
                                'table' => 'users',
                                'field' => 'email',
                                'messages' => array(
                                        'recordFound' => 'Email already taken'
                                )
                        )
                        )
                )
        ));

I have changed my controller to this:

public function addAction()
    {
        $modelUsers = new Model_Users();
        $userId = $this->_getParam('userId');
        $form = $this->_getAddForm();

        if ($userId) {              
            $populateData = array();

            $user = $modelUsers->fetch($userId);

            if ($user instanceof Model_User) {
                $populateData = $user->toArray();
            }

            $form->populate($populateData);
        }

        $request = $this->getRequest();

        if ($request->isPost()) {
            $email = $this->getRequest()->getParam('email');
            if (strtolower(trim($email)) == $modelUsers->fetchByEmail($email)) {
                // change $this->_user->getAccount()->getEmail() to retrieve the user's current email address

                // remove validator from form
                $form->getElement('email')->removeValidator('Db_NoRecordExists');
            }

            $post = $request->getPost();

            if ($form->isValid($post)) {
                $values = $form->getValidValues($post);
                $data = array(
                    'firstName'     => $values['firstName'],
                    'userTypeId'    => 2,
                    'lastName'      => $values['lastName'],
                    'email'         => $values['email'],
                    'userName'      => $values['userName'],
                    'password'      => $values['password'],
                    'role'          => $values['role']
                );

                if ($userId) {
                    $user = $modelUsers->fetch($userId);
                    if ($user instanceof Model_User) {
                        $user->setFromArray($data);
                        $success = $user->save();
                        if ($success) {
                            echo Zend_Json::encode(array('status' => self::STATUS_SUCCESS, 'message' => 'Successfully updated the user!'));
                            exit;
                        }
                    }
                } else {
                    $user = $modelUsers->createRow($data);
                    $success = $user->save();
                    if ($success) {
                        echo Zend_Json::encode(array('status' => self::STATUS_SUCCESS, 'message' => 'Successfully added the user!'));
                        exit;
                    }

                }
                echo Zend_Json::encode(array('status' => self::STATUS_FAILED, 'message' => 'user not added'));
                exit;               
            } else {

                $errors = array();
                $errors = $form->errors();              

                echo Zend_Json::encode(array('status' => self::STATUS_ERROR, 'data' => $errors));
                exit;

            }
        }

        $this->view->form = $form;
        $this->_helper->layout->disableLayout();

    }

Model:

public function fetchByEmail($email)
{
    $email=fetchOne('SELECT email FROM users WHERE email = $email');
    //$select->where('email=?',$email) ;
    //$student = $this->fetchRow($select);
    return $email;
}

But still this is not working

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:23:41+00:00Added an answer on June 11, 2026 at 10:23 am

    One simple way you can solve this problem is to remove the validator from that form element when the form is being edited. You may also want to keep the validator if they are attempting to change their email address since they shouldn’t be able to change their email to one that already exists in the database.

    Leave the validator in your Zend_Form class, add this code only when a user is being edited.

    if ($this->getRequest->isPost()) {
        $email = $this->getRequest()->getParam('email'); // get email from form
    
        // if email address has not changed, remove validator from form
        if (strtolower(trim($email)) == $this->_user->getAccount()->getEmail()) {
           // change $this->_user->getAccount()->getEmail() to retrieve the user's current email address
    
           // remove validator from form
           $form->getElement('email')->removeValidator('Db_NoRecordExists');
        }
    
        // validate form
        if ($form->isValid($this->getRequest()->getPost()) {
            //...
        }
    }
    

    So what you are doing is removing the Db_NoRecordExists validator from the form element when the form is being edited, and only if they are not attempting to change their email address if they are allowed to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a zend framework based email project and I'm following some code
I'm working on a project now that isn't based on Zend Framework, however I
I'm working on a zend project which has functionality based on user logged minutes.
I am currently working on a project developed using Zend Framework, based on the
I have a web project working fine in JBOSS with form-based auth. But when
I'm working on a larger Web based Project, that probably will have to handle
I have a view based project working with a UINavigationController. The RootViewController performs operations
Currently working on a flex AIR project based on PureMVC framework. There was a
Hi I'm currently working on some php - zend framework project on my osx
I'm working on a project based on Symfony2 framework, and I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.