views:

30

answers:

1

I have a form that is using an anchor name as it's action so that when the form is submitted it is it goes straight back to the form (for example 'www.domain.com/page#contact-form). The idea is if there are any errors then it'll go straight to the form (that's near the bottom of the page) so you can see the errors and continue filling in the form. If the form is valid, I want it to redirect to another page (for example www.domain.com/another-page). The problem is that the redirect url still has the anchor text in the url (in the above example it is www.domain.com/another-page#contact-form).

I am using

$this->_helper->redirector->goToRouteAndExit(array(), 'another-page', true);

to goto the another-page route. I have tried setting the url specifically but that doesn't fix it either.

How do I redirect to another page and remove that anchor text from the url?

A: 

I would have presumed that you could do something like:

if ($this->_request->isPost()) {
   if ($formObject->isValid($this->_request->getPost())) {
      // do something
      $this->_redirect('/my/new/url/');
   } else { // if error
      // do something else
      $this->_redirect('/my/original/url/#anchor);
   }
}

Any use?

Edit: Assuming that you are using Zend_Form/Zend_Dojo_Form

lintal
I am using Zend_Form. When I try to do a redirect I lose the form data. If you have ever entered a form and got the info wrong, most of the time it will display the form and your data again, where-as when I do a redirect it just shows the form - which is frustrating when you have just spent 5(ish) minutes filling in this big-ass form =(I have done a work-around, though. If the form is valid, then it hides the form and echos a success message, so the user has some sort of feedback explaining where the form has form.
Dickie
I have never tried encoding the anchor into a form action before but, when declaring your form, you could try to include that. I am taking the assumption that if the user is completing the form then they will be in that area of the page and need redirection back there on error. Finally remove the redirect statement I wrote above if not valid from your controller.Other options could include using sessions to store the form data, but I would try and avoid that complexity if possible.
lintal