Hi, I’m trying to create a popup which I can insert the text of a coupon code, clicking the OK button should only work when the typed code exists in the code database, and if it does, perform an action and delete the typed code from the list of codes in the database
Create a Data Type called ‘Coupon’ with a text field for ‘code’, and any other field which stores what the coupon does (e.g. Discount Percentage, Free Items, X£ off etc…)
Create a few Coupons. (You can either create them and manually modify the code to whatever you’d like, or you can programmatically generate random strings using the ‘calculate formula > generate random string’ operator.
After the user types in their code, press the ‘Apply’ button.
The apply button will then run a search for Coupons & return the coupon.
I would save the coupon to a custom state on the page, so that the page can then display the right information about the coupon/discount.
I personally wouldn’t delete the coupon from the database. Create a yes/no field (or even better a date/time field to store the date when it was used) called ‘used’ and mark the coupon as used. When searching for coupons, search for coupons that have not been used.
NOTE:
This is a bit more advanced, and its something which often gets overlooked especially in Bubble.
Privacy rules are important for Coupons. The Coupon datatype should not be public, and it should not be searchable. Otherwise anybody with basic knowledge of web-development could query your coupons from your servers and use them freely.
I would advise to set the datatype as completely private, and then create a backend workflow which ignores privacy rules and run the coupon search from there.
i tryed this but the ok button doesnt respond, i want it to close the pop up and open the next level while cuopon is available and if the cuopon isnt , it will show error massage, but for now its or working with any input , or dont work at all cause the “only when” setting prevent it ,