The client requested that while at tradeshows, they have some way of giving away books through a form on the website, using coupon codes that they would be handing out at their booth.
To accomplish this, I went to Random.org to generate hundreds of coupon codes that included a mix of integers, uppercase letters, and lowercase letters and saved it as an Excel file. With this list, the team was able to do a mail merge and print coupon codes, while I used the file to create a new table of coupon codes within the Drupal database. I also made sure there was a binary field that indicated whether that coupon was valid ("1") or used ("0").
I then wrote a custom module that alters the Webform used to collect the book selection, coupon code, and shipping and contact information.
The custom module itself added a validation function to the validation stack which compared the submitted result to the table, using:
If the coupon code was found and the status was "1," the validation would pass and the form would submit, and upon submit, the "status" column would change to 0. If either the coupon code was not found or if it were found and the status was "0," the form would return with a "Coupon code is invalid." error message.
Later, the client wanted to add some functionality: 1) during one event, they wanted to make sure each coupon corresponded to only one book, and 2) during another event, they wanted to build a similar landing page to go with a raffle drawing they were doing once every hour. I built that page so that winners could input their winning ticket number. I also built an admin for the client so they could enter the winning numbers themselves.
I also worked with the client's fulfillment company to build an integration so that instead of outputting to a spreadsheet, the customer's information was passed to the fulfillment website to automate the order process.
Drupal Custom Module