开发者

validate code entered into a form

i am trying to setup a simpl开发者_StackOverflowe javascript form. User must enter correct discount code. If not they get an error message. if correct, they are directed to another website. any help would be greatly appreciated!


This kind of verification should be done server side, not client side (hence not in javascript) for security reasons.

If you still want do this verification, then look for AJAX methods.


Resources :

  • The art of web - JavaScript: Form Validation using Ajax


This could be done on submit using jQuery. For example $(selector).load("/ValidateCode.php?code='"+$("#code").val()+"'"); (or something similar).

However the actual validation would be in the server-side validation page. The reason being that you would have to validate the code against all other codes - so to do this in pure jQuery you would have to have all codes somewhere in the source code so users could simply use the source code to obtain a valid code.

So the answer is: yes you could validate the code in JS / jQuery, but it is best to validate in a server-side page which is loaded by JS / jQuery - thus the application is still secure and the page still appears seamless (i.e. it does not refresh). The validation page could just output an image of a tick or cross or something, which you load into a span next to the code entry box.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜