I have a fancybox with input and submit button. On submit I generate an url, and then I want to close the fancybox and redirect to the generated url.
The redirect is working but is opened in the Fancybox. The I tried the suggestions in
how-to-redirect-zend-login-form-in-a-fancbox-iframe-with-php-without-any-js-on,
fancybox-close-from-within-iframe-and-take-parent-page-to-the-link
and similar.
The option mentioned in close-fancybox-2-window-and-redirect-parent-window is not suitable/desirable since 1. I am using a fancybox defined in a seperate file for the entire application and adding a afterClose callback within the fancybox dimensions would have implication for all other fancyboxes (I don't want to dimension every fancybox seperately), and 2. I want to be able to close the fancybox on cancel without redirect.
The desired solution is to close the fancybox and redirect from the controller. The thing is that my url is dynamic and generated on submit, meaning I cannot set the url on opening the fancybox. But since the redirect is working I suppose closing the fancybox shouldn't be to hard.
What I have:
Choose.phtml is opened in a fancybox from chooseAction in index.php. In the fancybox I select option A or B and submit. On submit the action createOption is called, the Option is inserted in the database and the id (say '123') is returned. This id becomes part of the url http://www.example.com/option/edit/id/123.
Then, here comes the relevant part, in my controller I now have:
echo '<script type="text/javascript">window.location.href = '.
$this->_helper->redirector->gotoRoute( array("module" => "option", "controller" =>
"create", "action" => "edit", "id" => $newOptionId ) ,"newOption", TRUE).';
parent.jQuery.fancybox.close(); </script>';
The url part is looking good since it does redirect to the desired view. Only problem is it is displayed in the fancybox so the fancybox.close part remains the problem.