I want to accept coupons on my web app. I am using javascript for feild validation and want to validate the coupon during this process also.
I have a view that contains all valid coupon codes.
Is there a javascript method for doing this? I tried the following but it does not seem to work. all_promos is a hidden field that does a @dbcolumn to retrieve all coupon codes. Any suggestions?
No, not JavaScript! Well, the preferred/secured way to validate a coupon code (or anything that has to deal with money and pricing) is to submit the form. When you submit the form, only the server will have control of the results.
In a nutshell:
ensure code is valid
Dim vwValidPromos As NotesView, docPromo As NotesDocument, promoAmt As Currency
Set vwValidPromos = promoDB.GetView( “(ValidPromosView)” )
Set docPromo = vwValidPromos.GetDocumentByKey( webDoc.promo(0), True )
If docPromo Is Nothing Then
Goto YourPromoIsNotValidSub 'preferably, display the same page with the error in red text
I am doing all the discounts on a server agent, I was just wanting to inform the user (before submission) that their entry is invalid. Javascript pop-ups wirk great for validation, but I am not sure how to use JS for this since the values are not on the form.
For now, I took your advice and after submission, if the code is invalid, then I return them to the document in edit mode, with a message on the form informing them of the error.
Javascript only works if you can access the values from the same screen. If you don’t want people to be able to “View Source” and see a list of the coupon codes then the only way to do it is to take a sever hit. If you don’t care… make sure that “Generate HTML for all fields” is check on the form properties. Then the dblookup field on your form will be accessable by Javascript.
You can also use the view as a javascript file accessed via a URL. Set the view to “Treat contents as HTML” and embed it on a page set to “Treat contents as other”,“text/javascript”. Use column formulas that result in setting JS variables to the value of the valid coupon codes (perhaps as an array, with the intial array setup done on the page). Again, as Joseph said, this is COMPLETELY INSECURE, so don’t use it if it’s part of an application that could stand to cost anyone a lot of money or legal problems. All it will do is make it less convenient for people to get the information – they can download the “javascript file” themselves to take a look.