TinyMce and Captcha collide in my cakephp application

I was struck in a very strange problem today. I was using captcha component to create and set a captcha session and image for view section. Next is the snippet of create function which i used to load component. I will be pasting JcaptchaComponent source code at the end for anyone who may want to take a look into the matter more precisely (however i feel the componet itself should be quite innocent)

And here is a function which i did used to ajax call from a view to refresh the captcha (View captcha post or download captcha here).

Everything was going fine until i submitted the form data and captcha validation started to fail. I have been using the same form in my admin section (however i did not use captcha there) for adding and editing the charity details and in the front end for users to add information, and it worked just fine there.

On my submitting the form, before matching the captcha value with form textfield value the system created a new captcha session and hence it did not match. Although I was creating the captcha only when rendering the form and once again if validation for any of the fields failed, it was quite strange and still a mystery to me.

I started debugging in my controller functions, applying and printing captcha values in beforeRender(), beforeFilter() but it did not help. When commented the $this->data property which was being used to fill the form field values, the re generation of captcha stopped. Then i started to think that the call was happening in some model class functions. But i had to drop that idea as soon as i realized that same model functions were working just fine in another areas (add charity in front). Now i concentrated on the rendering of form field values from $this->data and started debugging by commenting the input fields one by one.

Now the turn was of the culprit and it was a tiny mce editor textarea field which was being populate from data from the database. This is the text snippet which forced my cakephp application to generate the new captcha but unfortunately i am not fully clear how and why it happened.

Fortunately i was able to fix it by removing the code from it but now i am staring to fear that it must come back again if someone copy-pasted the code from some page which i did there.

Suggestion are most welcome and it someone like to help i can give more information just ask me to do so.

And finally here is the component code

Thanks for your time to read it!

One thought on “TinyMce and Captcha collide in my cakephp application

  1. I’m guessing that by now you’ve resolved this. ;)

    I have experienced a similar issue with regard to this: It appears that TinyMCE breaks the use of canvas objects. All other canvas objects – not just on the current page, but the whole browser session – will fail to render until the browser is shut down and reloaded.

    This happened for me in both Firefox 5 and Chrome 13.

    I’m still looking for a way around this. Feel free to let me know if you’ve found a way around the canvas issue.


Leave a Reply