Friday, July 29, 2011

Invalid fields when loading edit page

My app uses the native Auth component and my User model is doing
something I've never seen before. I'm hoping someone here can offer
some insight.

The app offers a way to register (i.e. create a brand new user) or to
be invited. The User::invite() action accepts a unique invite code,
uses that to pull the invited user id and redirects to the
User::register() method passing along the user_id. The
User::register() method in this scenario is essential an edit form. On
the face of it everything works great except that when the form
displays, all of my inputs are marked as invalid even though I'm
simply loading the form. Nothing has been submitted.

If I don't populate the $this->data array, no fields are marked. If I
do, however, the error messages appear like Christmas lights all over
my form. As far as I can tell, there's nothing special about what I'm
doing to populate the data array, but maybe I'm just blind to it at
this point. In the event that we've been redirected to
User::register() with a user id value, the data array gets populated
as:

# Populate existing data, if any
$this->data = $this->User->find(
'first',
array(
'contain' => false,
'conditions' => array( 'User.id' => $user_id ),
)
);

That's it. If I remove that, all is well. I've also tried tweaking it
so that only those fields that I absolutely need for the form are
retrieved, but that makes no difference.

Any thoughts would be much appreciated. This has been going on for
months and the only way I've found to get around it is to suppress
validation all together by emptying the validate array in this
scenario -- obviously a non-optimal solution.

Thanks.

Rob

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: