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

  • Home
  • SEARCH
  • 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 3361754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:11:27+00:00 2026-05-18T03:11:27+00:00

Have some validating problems which seem to appear only when using the Auth component.

  • 0

Have some validating problems which seem to appear only when using the Auth component.
I have 4 fields in my register form: username, password, password_confirm and email.

I also have the multivalidatable behaviour attached to my User model. Here are the rules which apply to the register form:

var $validationSets=array(
    "register" => array(
        "username" => array(
            "usernameFieldNotEmpty" => array(
                "rule" => "notEmpty",
                "message" => "You did not enter the username!"
            ),
            "usernameValid" => array(
                "rule" => "__alphaNumericDashUnderscore",
                "message" => "The username you entered is not valid!"
            ),
            "usernameExistsInDatabase" => array(
                "rule" => array("__existingRecord", false), 
                "message" => "The username you entered has been already registered in our database!"
            )
        ),
        "password" => array(
            "passwordFieldNotEmpty" => array(
                "rule" => "notEmpty",
                "message" => "You did not enter your password!"
            )
        ),
        "password_confirm" => array(
            "passwordConfirmFieldNotEmpty" => array(
                "rule" => "notEmpty",
                "message" => "You did not confirm your password!"
            ),
            "passwordsMatch" => array(
                "rule" => array("__fieldMatch", "password"),
                "message" => "The passwords you entered don't match!"
            )
        ),
        "email" => array(
            "emailFieldNotEmpty" => array(
                "rule" => "notEmpty",
                "message" => "You did not enter the e-mail!"
            ),
            "emailValid" => array(
                "rule" => "email",
                "message" => "The e-mail you entered is not valid!"
            ),
            "emailExistsInDatabase" => array(
                "rule" => array("__existingRecord", false), 
                "message" => "The e-mail you entered has been already registered in our database!"
            )
        )
        /*"language" => array(

        )*/
    )

Here is my register form:

<?php echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'register')));?>
<fieldset>
    <legend><?php __('Add User'); ?></legend>
<?php
    echo $this->Form->input('username');
    echo $this->Form->input('password', array('type' => 'password', 'value' => ''));//value='' - resets the password input on any error on the page
    echo $this->Form->input('password_confirm', array('type' => 'password', 'value' => ''));
    echo $this->Form->input('email');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>

Now, everytime I submit the form EMPTY, the password field, although empty, passes all validation tests (I tried putting value => '' in the code, but it’s useless).
Also, the email input seems to pass the 'notEmpty' test and the error shown is that The email is not valid

I’ve looked over all my code but couldn’t find any solution.

  • 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-05-18T03:11:27+00:00Added an answer on May 18, 2026 at 3:11 am

    I’ve managed to do a couple of “hacks” so the problem is solved for now.
    Don’t think this is the most appropriate way of doing it, but it might get in handy for other users having my problem:

    Firstly, in my UsersController, I wrote this snippet, so if the password field is left empty by the user, reset it to '' before validation:

    if($this->data['User']['password'] == $this->Auth->password('')){
                $this->data['User']['password'] = '';
            }
            $this->User->set($this->data);
            if($this->User->validates()){ //post validation login }
    

    The second problem was the e-mail validation. Oddly, I got this problem fixed by changing the order of the rules in the Multivalidatable Behaviour. So, from:

    "email" => array(
            "emailFieldNotEmpty" => array(
                "rule" => "notEmpty",
                "message" => "You did not enter the e-mail!"
            ),
            "emailValid" => array(
                "rule" => "email",
                "message" => "The e-mail you entered is not valid!"
            ),
            "emailExistsInDatabase" => array(
                "rule" => array("__existingRecord", false), 
                "message" => "The e-mail you entered has been already registered in our database!"
            )
        )
    

    I now have:

    "email" => array(
                "emailExistsInDatabase" => array(
                    "rule" => array("__existingRecord", false), 
                    "message" => "The e-mail you entered has been already registered in our database!"
                ),
                "emailValid" => array(
                    "rule" => "email",
                    "message" => "The e-mail you entered is not valid!"
                ),
                "emailFieldNotEmpty" => array(
                    "rule" => "notEmpty",
                    "message" => "You did not enter the e-mail!"
                )
            )
    

    I don’t know whether this was intended or not, but it seems like the last rule which isn’t fulfilled is the one displayed. To my logic, the rules would have been arranged in their order of appearance, so if the first one doesn’t apply, stop checking and display it.

    I repeat, I don’t know if this is the right approach, but I seem to have worked out these problems.

    If you have anything to add up, please do so!

    EDIT
    Found the ‘official’ explanation in the Cake 1.3 Book. It says:

    By default CakePHP tries to validate a field using all the validation rules declared for it and returns the error message for the last failing rule. But if the key last is set to true for a rule and it fails, then the error message for that rule is returned and further rules are not validated. So if you prefer to show the error message for the first failing rule then set 'last' => true for each rule.
    

    So, another approach to my problem is to set the validation rules in their order of appearance and add a last key to the rule array.

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

Sidebar

Related Questions

I have a form with multiple fields that I'm validating (some with methods added
I have some client-side validation against a text box, which only allows numbers up
I have some ASP.NET web services which all share a common helper class they
I have some C# / asp.net code I inherited which has a textbox which
Hi have some forms that I want to use some basic php validation (regular
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing 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.