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 4608444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:50:45+00:00 2026-05-22T00:50:45+00:00

I have a registration form that a user can access via invitation. For example,

  • 0

I have a registration form that a user can access via invitation. For example, an invited user can go to /users/register/[invite_code] and get a registration form that is partially populated. I’m seeing something I didn’t expect:

If the invite code is valid, we return the user structure and set that in $this->data so that the form is automagically pre-populated. The pre-population works, but when the form loads, the data validation errors are displayed as though I’d submitted the form. I see a lot of “[Field name] cannot be empty” when a value has been pre-populated.

In response to questions, the register action is called to both display and submit the form. The code looks like this:

public function register( $invite = null ) {
  # Handle a submitted registration
  if( !empty( $this->data ) ) {
    # Do stuff...

    if( $this->User->save( $this->data ) ) {
      $this->Session->setFlash( 'Welcome. Thanks for registering.', null, null, 'success' );
      $this->redirect( $this->Auth->redirect() );
    }
    else {
      $this->Session->setFlash( 'Oh noz. There\'s a problem with your registration.', null, null, 'validation' );
    }
  }

  # If an invite is passed, pull the user attached to that invite.
  if( !empty( $invite ) ) {
    # Attempt to pull the user that owns the invite

    if( empty( $user ) ) { # Unrecognized invite code
      # Do stuff...
    }
    else { # Invited user found
      if( !empty( $user['User']['password'] ) ) { # Invited user has already registered
        # Do stuff...
      }
      else { # This is the invited user
        $this->data = $user;
      }
    }
  }
}

Thanks.

UPDATE

After coming back to this, the problem comes when I assign the user to $this->data. When I remove that, no validation errors. Unfortunately, no pre-population either. I need the latter, so I need to find a way of setting the data points without triggering the error messages.

UPDATE 2

If I dump $this->User->invalidFields(), even as early as the first line of UsersController::beforeFilter(), the array is populated with invalids. How is this possible? What could I possibly be doing that early in the request to cause this?

UPDATE 3

I’ve also noticed that as I enter UsersController::beforeFilter(), the value of $this->User->id is already set. I have no idea where or why, but this seems significant. As far as I know, the first step into the actual application code is the relevant controller’s beforeFilter method and the user id is set on the way in.

  • 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-22T00:50:45+00:00Added an answer on May 22, 2026 at 12:50 am

    The controller loadModel() function, unfortunately, sets the id property in the model based on the first parameter on your action. That is a big annoyance that was removed in CakePHP 2.0. Nevertheless there is no code that will auto validate your fields after setting an Id, so my guess is that you have a component handling the auto validation or you have some code in your mode that will do it when the model is created.

    If you cannot find the code that is auto validating your data, or do not want to change it, I suggest you override loadModel() in your controller to remove the id assigment, or just use a named parameter for your action.

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

Sidebar

Related Questions

My idea: I have a database of users, each user has an autoincremented id
I need to create some simple form that will be use to registration a
I have a website that is using SMF forum (simplemachines.org). I have been using
I am working on a Zend Framework application with PHP. I have a form
I am creating a registration form using PHP and jquery with ajax. Each field
I'm using Zend Framework and I currently have an existing form using zend-form which
I have an issue at work where we have just started using scrum as
When a user registers on my site, I want to be able to check
I have the following code which will check to see if the following fields
To keep things brief I need to direct you to my website. Please visit

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.