To include anchor in a URL, provide the id with the '#' key in the
URL. If your anchor ID is 'foo', you'd use something like:

'controller' => 'xxx', 'action' => 'yyy', '#' => 'foo'

... in the form action. You need to specify it there, and not in a
controller redirect, because the page is not reloaded when there are
validation errors. The form submits to the same URL, and, if there are
NO errors, the request is redirected. Otherwise, the view for that URL
is rendered as requested, only this time displaying validation
errors..

OT FYI: You can use any HTML element with id="foo"; there's no need to
use an A tag (I believe that that use of A is deprecated in HTML5).


On Mar 19, 11:45 pm, Johnny Ferguson <[email protected]> wrote:
> Hi,
>
> I've successfully set up a contact form in cakePHP, and when
> validation rules in my model don't pass, the form is reloaded with all
> my validation errors displayed properly. That battle was won :)
>
> Now for the tricky part.
>
> Can anyone think of a way to not only have the form page reload with
> error messages, but jump to an anchor link at the top of the form if
> errors are present? I'm sure I could use javascript for this, but as
> it stands I can't count on users having javascript enabled. Currently
> when the form reloads with error messages in place, users have to
> scroll down from the top of the page, and I see this as a slight
> problem.
>
> Obviously CakePHP is smart enough to redirect to an appropriate URL
> when validation fails, all I need to do is add #myAnchor to the end of
> that URL somehow. Any ideas?
>
> I've thought of adding a line to my beforeFilter that says something
> like
>
> 1. if we're visiting the form page
> 2. and if some error flag variable is set
> 3. catch the URL somehow
> 4. Add the anchor to the end
>
> But I'm not sure on the specifics of how I'd go about this, and as
> this filter would run before the any page in the controller runs, I
> have concerns about efficiency. Any ideas?
>
> Thanks in advance for your input.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to