We would like to sell numbered tickets for a raffle. According to the regulations we need to meet, we have to sell tickets that have unique numbers from a predetermined set (e.g. we have tickets numbered 1-500). How can we sell these tickets with email receipts that go to the buyer, including the ticket numbers?

Ideally, it would be possible to sell more than one ticket in a transaction and send a receipt to a buyer saying that they bought tickets x, y and z or failing that three emails listing the ticket numbers.

We've used a Drupal webform with the submission id as the ticket number in the past, but this only allows us to sell one ticket per transaction. It seems like we might be able use Civirules to send receipts with ticket numbers, but I'm not seeing a way to do that without custom code.

  • I can think of several approaches, but none that would allow multiple tickets per transaction without writing custom code. Nov 5, 2020 at 15:57
  • Thanks Jon. Would there be a better way to sell tickets one by one from a pre-defined set of numbers than using webform submission id (which is a little painful, as it limits us to sequential numbers)?
    – Lars SG
    Nov 5, 2020 at 20:41
  • 1
    All the one-by-one approaches would be sequential number approaches. Custom code-wise, the most "elegant" approach would probably be a "Raffle Ticket" entity, each record could have a contact_id to link it to a person. A simpler approach would be a Setting called "next ticket #" that would update any time tickets are sold. I think you're looking at code either way though. Nov 6, 2020 at 20:04
  • What about just adding a bit of code that essentially adds the same info to the webform n-1 times on webform submission? That might be simpler than doing an entity. Then buyers would get one email for each ticket number, but that's not a big problem for our use case. Potential pitfalls?
    – Lars SG
    Mar 19, 2021 at 16:46

1 Answer 1


My solution to this isn't elegant, but it gets the job done. I simply added a little code with hook_webform_submission_insert that takes the original webform submission data and resubmits the essential details to a second webform as many times as the user bought tickets. That second webform serves as the official list of tickets sold and sends an email for each submission to the buyer (so the buyer gets three emails with different ticket numbers if they bought three tickets). This works fine as long as your ticket numbers are sequential and increasing. You can add more tickets in a higher range by adding higher tickets numbers by changing the next submission value for the webform, but you can't add tickets with a lower number.

function wildsight_raffle_tickets_webform_submission_insert($node, $submission) {
  if ($submission->nid == 210) {
  $node_out = node_load('211');
  global $user;

  $data = array(
    'first_name' => $submission->data[3][0],
    'last_name' => $submission->data[4][0],
    'email' => $submission->data[14][0],
  module_load_include('inc', 'webform', 'webform.module');
  module_load_include('inc', 'webform', 'includes/webform.submissions');
  $number_of_tickets = $submission->data[24][0];
  // This methods will arrange $data in the right way
  $data_out = _webform_client_form_submit_flatten($node_out, $data);
  $data_out = webform_submission_data($node_out, $data_out);
  while ($number_of_tickets > 0) {

  $submission_out = (object) array(
    'nid' => '211',
    'uid' => $user->uid,
    'sid' => NULL,
    'submitted' => REQUEST_TIME,
    'completed' => REQUEST_TIME,
    'remote_addr' => ip_address(),
    'is_draft' => FALSE,
    'data' => $data_out,

    webform_submission_insert($node_out, $submission_out);
    webform_submission_send_mail($node_out, $submission_out);
    $number_of_tickets -= 1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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