Tuesday, January 29, 2013

Re: Validating multiple fields problem

CharactersEvent would have just been the join table in a HABTM relationship between the Character model and the Event model if it wasnt for the fact that I needed to also assign a role to that record. Thus, it got promoted into needing its own Model and now is part of a HasMany/Belongs to with the Character, Event and Role models. Since this record is being created when I save the Event form, all the request data is stored in $this->Event->data which is what I am checking to make sure the user didn't add the same character twice or if the event even allows that many characters to be assigned to it. Basic validation stuff except for the fact that I am validating against data that is apparently stored in another model.

When I put a debug statement before the validation, all the data is there as I would expect, but.. the strange thing is, it prints twice. The second time, the data is no longer in $this->Event->data as it seems to have been cleared which then makes my for loop fail. I have no idea why it gets called a 2nd time as it returned true to the validation rule (debug confirmed this) the first time. I thought it might have had something to do with the fact that I had 2 different fields for the same kind of role (this is ok, the event type allows for multiple roles to be assigned to this event) but when I changed the code to have 3 fields instead of just 2, it still only ran twice, again failing the 2nd time. Is there maybe a way I can save the data to a session then use that? It seems really hacky but I'm not sure why cake is working the way it is. Thanks for the help.

~Michael


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: