PDA

View Full Version : Dynamically change regex in textfield problem



altamirador
18 Aug 2009, 6:33 AM
Hi !

Once again, I need help from the community ! I have a form from which I wish to validate a captcha that I have created. I load the captcha image from php and this part works pretty well. At the same time it loads, I pass the captcha value in a cookie. This works well also.

But, here's what I'm trying to do: When I get the image refreshed, I get the cookie and change the regex value from he form's field:


var RegularExpression = new RegExp(readCookie('captcha')); // captcha value converted to regular expression
Ext.get('FCaptcha').regex = RegularExpression; // assign to field named FCaptchaThat does not generate any error however, the field does'nt validate ??

Any ideas ?:((

It's the part in blue I'm not so sure about !!!


Altamirador

Condor
18 Aug 2009, 6:35 AM
Ext.getCmp('FCaptcha').regex = RegularExpression;
Ext.getCmp('FCaptcha').validate();

Animal
18 Aug 2009, 6:36 AM
What's the cookie value? Is it a valid String to be passed into a RegExp constructor to get a value RegExp from?

Stop in debug and find out! And test the resulting RegExp on the command line to see if it does what you think it does.

altamirador
18 Aug 2009, 6:40 AM
Thanks !

It's just a simple string like '12ji3pl' and the regexp returns /12ji3pl/

altamirador
18 Aug 2009, 6:44 AM
Solved !

Looks like the cookie is not ready when I assign it. Basically, I'm getting the old cookie assigned to the field.

I need to find another approach.

Thanks for your inputs !

Altamirador !

Condor
18 Aug 2009, 6:56 AM
You are completely killing the captcha concept!

The whole point of this kind of validation is that a script can't generate an automatic response. Did you forget that a script can also read a cookie value?

altamirador
18 Aug 2009, 10:07 AM
Yes you are right to a certain extent...My cookie is encrypted...