Hi, I had the same problem as you. I was not able to use javascript to
redirect (using location.href), got error message about no access to
the directory. The history.back() doesn't work too well for me because
user could be trying to save but encounter validation error and after
several times, decided to cancel the operation, but the history.back()
will return to just one step behind, and not to the main list.

Here is how I solve it, basically make use of the 'name' tag and check
for the button pressed in controller function to redirect accordingly.
This should also solve the cross-browser issue.

In the view, I added the following buttons.

=====

..... Start of form and elements code .....

<div class="button">
  <?php echo $form->submit('Save Job Type', array('div'=>false,
'name'=>'submit')); ?>
  <?php echo $form->submit('Cancel', array('div'=>false,
'name'=>'cancel')); ?>
</div>

..... End of form code .....

=====

At the beginning of my controller add function (for example), I do
this first.

if (array_key_exists('cancel', $this->params['form'])) {
  $this->flash('Cancelled adding new job type.','/job_types');
}

... Rest of the data validation and saving logic ...

===

On Sep 12, 6:08 am, integrator <[EMAIL PROTECTED]> wrote:
> I am not satisfied with this solution. For instance when I edit an
> item in the list and save the changes I want to go back to the list I
> had before and not to e new list with a different ordering. Alse when
> I edit an item ,and I get an input error i can't go back to list with
> the javascript function.
>
> I looking for a more sofisticated solution.
>
> On 28 aug, 12:13, draikin <[EMAIL PROTECTED]> wrote:
>
> > Thank you all for posting solutions. I solved the problem with the JS
> > solution from clemos. It works like I want and I will dare that some
> > users of my applikation don't like JS.
>
> > draikin
>
> > On 25 Aug., 14:54, "Marcin Domanski" <[EMAIL PROTECTED]> wrote:
>
> > > The Formhelper does NOT need JS :)
>
> > > As fot the OP problem - you can save the actual page to the the session.
> > > If there is a page in session - get the url, if its different then the
> > > actual - save the actual (you have the one for  backin the var).
> > > It has drawbacks but its closest you can get.
>
> > > --
> > > Marcin Domanskihttp://kabturek.info
>
> > > On Mon, Aug 25, 2008 at 12:07 PM, clemos <[EMAIL PROTECTED]> wrote:
> > > > Hidraikin
>
> > > > I think we can consider CakePHP actually "needs" Javascript.
> > > > Of course you can use Cake to develop javascript-free apps, but lots
> > > > of Cake features, for example some of the FormHelper functionnalities,
> > > > actually require javascript...
>
> > > > You could use a code that use both, like:
> > > > controller: $this->set("referer",$this->referer());
> > > > view: $html->link("go
> > > >back",$referer,array('onclick'=>'window.history.back(); return
> > > > false'));
> > > > Like so, Javascript enabled browser will use the Javascript function,
> > > > while Javascript disabled browser will use the $referer href.
> > > > Of course, if the browser supports neither js nor referer, the link
> > > > will likely fail; but it's still the most widely compatible way I can
> > > > imagine...
> > > > Note that the JS function and the referer link may not lead to the
> > > > exact same page; this needs to be well tested to see if there are
> > > > differences...
> > > > Well, you may also force the referer to be passed through named
> > > > variables (something like : $html->link("go
> > > > there","/controller/action/whatever/referer:".urlencode($this->here));
> > > > ), but you'll need to do it for each link, and it'll mess up your
> > > > "nice urls" a little bit...
>
> > > > ++++++
> > > > Clément
>
> > > > On Fri, Aug 22, 2008 at 4:02 PM,draikin<[EMAIL PROTECTED]> wrote:
>
> > > >> Hi clemos,
>
> > > >> thank you for your solution that I read also. But just like $this-
> > > >>>referer() doesn't work for all browsers javascript doesn't work for
> > > >> all users, as there are some users who don't like javascript. But if
> > > >> there is a need for javascript in cakephp apps anyway (i don't know if
> > > >> this is so), your solution is the easiest.
>
> > > >>draikin
>
> > > >> clemos schrieb:
> > > >>> Maybe I didn't understand your problem, but ...
> > > >>> Why don't you give a try to my good old plain javascript solution ?
>
> > > >>> <a href="javascript:window.history.back()">goback</a>
>
> > > >>> The link above will get youbackjust like your "back" 
> > > >>> browserbuttonwould...
> > > >>> You can evengobackfurther with "window.history.go(-10)" (ten 
> > > >>> pagesback)
> > > >>> No Cake, No PHP, just simple javascript...
>
> > > >>> $this->referer() doesn't work for all browsers, cause the referer must
> > > >>> actually be sent by the client (IE doesn't seem to send it all the
> > > >>> time).
> > > >>> +++++++
> > > >>> Clément
>
> > > >>> On Thu, Aug 21, 2008 at 7:35 PM,draikin<[EMAIL PROTECTED]> wrote:
>
> > > >>> > Thank you for your response. Yes, thats what I'm looking for. But 
> > > >>> > the
> > > >>> > problem is that $this->referer() seems not to work. So I will test 
> > > >>> > the
> > > >>> > bread crumb feature from the HTML helper.
>
> > > >>> >draikin
>
> > > >>> > teknoid schrieb:
> > > >>> >> You are probably looking for something like $this->referer()
>
> > > >>> >> Also there is a bread crumbs feature in the HTML helper, for 
> > > >>> >> something
> > > >>> >> more robust.
>
> > > >>> >> On Aug 21, 10:35 am,draikin<[EMAIL PROTECTED]> wrote:
> > > >>> >> > Hi,
>
> > > >>> >> > i'am searching for a solution for the following problem. I want 
> > > >>> >> > to
> > > >>> >> > have a link on the pages of my little cakePHP app to allow 
> > > >>> >> > togoback
> > > >>> >> > to the page where i come from. So as theback-buttonof the 
> > > >>> >> > browser.
> > > >>> >> > For example: I search for a subset of my database entries and 
> > > >>> >> > get a
> > > >>> >> > page with a table containing the results. Now i want to edit one 
> > > >>> >> > entry
> > > >>> >> > and so i klick on the 'edit' link in the first column of the 
> > > >>> >> > table. I
> > > >>> >> > edit the entry, save it and want togobackto the result page. If i
> > > >>> >> > dont want to edit, i will have a link on the edit page togobackto
> > > >>> >> > the result page.
> > > >>> >> > Did i describe the problem properly?
> > > >>> >> > Can anyone give me a hint? I tried to find a solution, but i 
> > > >>> >> > can't
> > > >>> >> > find what i need.
>
> > > >>> >> > Many thanks,
> > > >>> >> >draikin

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to