I have been working for a number of months on an application using CakePHP, and have for the most part found it to be a very congenial development environment. However, for the last few weeks I've been struggling with what looks to be some peculiar CakePHP behavior. Basically, I am trying to implement keyboard shortcuts (hotkeys) using simple Javascript event handling to capture keycodes, and then, via the browser's location.href property, route the user to the appropriate page. This approach works great most of the time. However, there are a couple of users for whom this approach causes the browser to route them to the login page rather than the desired page. I have rummaged through hundreds of postings here in the CakePHP Google group, and done dozens of Google searches through CakePHP documentation and numerous relevant blogs, but so far have turned up no clues to what the problem is.
Let me expand on the details a little bit: -The application I am working on mostly provides a few basic screens which present blocks of text followed either by simple forms, or by sets of link-type or button-type navigation choices. This part of the system works very well. -Recently, the product director wanted me to add hotkeys to speed up navigation. For example, in cases where the navigation consists of a short list of choices, he wants the user to be able to type a single digit associated with each choice. Thus, if there were 5 navigation choices, numbered 1 to 5, the user could either use the mouse to click on any of the 5 links for those choices, or type the individual digits 1 to 5 on the keyboard to select the corresponding link. In another case, there is an informational screen with a big Next button at the bottom. The product director wants the user to be able to go to the next page either by clicking on the Next button with the mouse, or by typing either the letter 'n' or a carriage return. -In order to implement the hotkey idea, I wrote some CakePHP code to generate simple Javascript to capture keycodes from keypress events, and then execute for particular characters a Javascript line of the form location.href = 'http://mysite.com/controller/action/arg'; which would cause the browser to switch to the specified page. [I used the Event class from the Prototype Javascript library together with CakePHP's Javascript Helper. I've attached an example of the kind of Javascript that gets generated to the end of this posting.] -When I wrote the hotkey-handling code several weeks ago, it appeared to work fine. In fact, it continues to work perfectly for me. Here's where it gets weird, though. About 90% of the time, when the product director himself tries a hotkey, he ends up on a login screen, as if he had been logged out. However, if he hits the back button, and then uses the mouse to make a choice on the screen he had been on, that works fine. So, he had not in fact been logged out. -The product director has so far tried this with 3 different browsers (IE, Firefox and Chrome) on 5 different machines in 2 different locations, and gotten the same bad behavior in roughly the same 90/10 bad/good behavior split. There are two other people involved with this project, as well. For one of them, like me, the hotkeys have never failed, while for the other user hotkey navigation has almost always worked, but has in fact failed a few times. So, can anyone provide some insight into this situation? Is there any reason why routing to a CakePHP page using Javascript's location.href should always work for some users, most of the time for other users, and rarely for yet others? Is there an alternative way to route to a CakePHP page from Javascript? Or is there some other way to implement a hotkey capability? Thanks in advance for any help or advice you can give. BillCavnar --------------------------------------------------------- Example of the generated Javascript code for handling hotkeys: <script type="text/javascript" src="/js/prototype.js"></script> <script type="text/javascript"> //<![CDATA[ Event.observe(window, 'load', function() { Event.observe(document, 'keypress', function(e){ var code; if (!e) { var e = window.event; } if (e.keyCode) { code = e.keyCode; } else if (e.which) { code = e.which; } var character = String.fromCharCode(code); switch(character) { case '1': location.href = 'http://http://mysite.com/worksheet/ show_answer/1'; break; case '2': location.href = 'http://http://mysite.com/worksheet/ show_answer/2'; break; case '3': location.href = 'http://http://mysite.com/worksheet/ show_answer/3'; break; case '4': location.href = 'http://http://mysite.com/worksheet/ show_answer/4'; break; case '5': location.href = 'http://http://mysite.com/worksheet/ show_answer/5'; break; } }); }); //]]> </script> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
