0

I have a requirement where users are supposed to enter their Code to validate before redeeming it. The page will have one field to enter the 'Code' and a button to verify if that code exists in Data Extension. I tried below code but it doesn't works.

    <html lang="en">
  <head>
  </head>
  <body>
%%[
if RequestParameter("submitted") == "submitted" then
   var @rows, @row, @rowCount, @CodeSumitted, @text1, @text2
   set @CodeSumitted = RequestParameter("Code")
   set @text1 = "Coupon Code is already Redeemed"
   set @rows = LookupRows("DEname","Code", @CodeSumitted)
   set @rowCount = rowcount(@rows)
   if @rowCount == 0 then
   set @text1 = "Coupon Code is valid"
   ]%% 
    <br> %%=v(@text1)=%% 
    %%[else]%%
   <br> %%=v(@text2)=%% 
    %%[endif]%%
    %%[endif]%%

<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<label>Code</label>
<input type="text" name="Code">

<input id="submitted" type="hidden" name="submitted" value="submitted" />

<input type="submit" value="Submit">
</form>

%%=IIF(RequestParameter("submitted") == "submitted", '<p>Your form has been submitted.</p>','')=%%

</body>
</html>
  • you output text2 in your if conditional, but never set it. You can likely get rid of that entire thing and just end it after the set text to "Coupon Code is valid" which will overwrite the initial text. You can then just <br> %%=v(@text1)=%% as both will have text1 set to correct value at that point. – Gortonington May 5 at 13:58
  • Correct! Thanks for noticing that @Gortonington. I am able to get it worked. Thank you! – Shantanu Punekar May 5 at 14:57
1

Moving from Comments to answer for easy reference:

You output text2 in your if conditional, but never set it. You can likely get rid of that entire thing and just end it after the set text to "Coupon Code is valid" which will overwrite the initial text. You can then just
%%=v(@text1)=%% as both will have text1 set to correct value at that point.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.