Re: Validation messages and redirect issue

2009-05-04 Thread brian

Yes, the redirect is the problem because it forces a new request to
the server. Validation messages are not the same as Session flash()
messages in that they're not saved in the session and available at a
later time.

If you consider a typical action involving a form submission, if
there's no save() (ie. because of invalid data) PHP will run through
the method without reaching a redirect. Because of this, Cake will
redisplay the action's view (the form). And FormHelper, in drawing up
the things its responsible for, will catch and display any validation
error messages. They're just view variables, in other words.

Someone else might have a better idea, but I think the easiest
solution would be to put the messages in the session and display them
in the same manner as session flash messages. That is, go around
FormHelper completely for displaying the errors. The downside is that
the errors won't be displayed inline with the form but, if you're
registration is on the homepage, I'm assuming there are only a couple
of fields. Even if not, it might not be so bad.

So, before redirection, check $this-User-validationErrors and, if
not empty, use $this-Session-flash() to transport it to the next
view. I suppose you'll need to loop through the array and grab
whatever errors are present. Use
die(debug($this-User-validationErrors)) in your action to see how
its laid out.

Does that make sense?

On Mon, May 4, 2009 at 1:07 AM, Eric Martin emarti...@gmail.com wrote:

 I'm having a problem getting validation messages to show up for a
 register/sign-up form. I have the form on the home page, which is
 accessed through a HomeController.

 The register/sign-up form posts to the UsersController, register
 function, which does the save. Regardless of the result, it redirects
 back to the home page but the form validation messages are gone.

 If I move the register/sign-up form to its own url/page, it all works,
 so I'm pretty sure that the redirect is wiping out the validation
 messages.

 Being fairly new to CakePHP, I'd appreciate any suggestions on how to
 make this work.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Validation messages and redirect issue

2009-05-04 Thread Eric Martin

Thanks brian! I've decided to either just send the user to the user/
register page if an error occurs (which will maintain the messages) or
do as you suggested.


On May 4, 9:05 am, brian bally.z...@gmail.com wrote:
 Yes, the redirect is the problem because it forces a new request to
 the server. Validation messages are not the same as Session flash()
 messages in that they're not saved in the session and available at a
 later time.

 If you consider a typical action involving a form submission, if
 there's no save() (ie. because of invalid data) PHP will run through
 the method without reaching a redirect. Because of this, Cake will
 redisplay the action's view (the form). And FormHelper, in drawing up
 the things its responsible for, will catch and display any validation
 error messages. They're just view variables, in other words.

 Someone else might have a better idea, but I think the easiest
 solution would be to put the messages in the session and display them
 in the same manner as session flash messages. That is, go around
 FormHelper completely for displaying the errors. The downside is that
 the errors won't be displayed inline with the form but, if you're
 registration is on the homepage, I'm assuming there are only a couple
 of fields. Even if not, it might not be so bad.

 So, before redirection, check $this-User-validationErrors and, if
 not empty, use $this-Session-flash() to transport it to the next
 view. I suppose you'll need to loop through the array and grab
 whatever errors are present. Use
 die(debug($this-User-validationErrors)) in your action to see how
 its laid out.

 Does that make sense?

 On Mon, May 4, 2009 at 1:07 AM, Eric Martin emarti...@gmail.com wrote:

  I'm having a problem getting validation messages to show up for a
  register/sign-up form. I have the form on the home page, which is
  accessed through a HomeController.

  The register/sign-up form posts to the UsersController, register
  function, which does the save. Regardless of the result, it redirects
  back to the home page but the form validation messages are gone.

  If I move the register/sign-up form to its own url/page, it all works,
  so I'm pretty sure that the redirect is wiping out the validation
  messages.

  Being fairly new to CakePHP, I'd appreciate any suggestions on how to
  make this work.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---