Limiting the Total Number of Submissions

Last updated on
30 April 2025

PHP snippet for limiting the total number of submissions to a Webform. Note that this is different from limiting the number of submissions per user, which is already an option in the webform configuration.

This snippet counts the number of submissions and when the max is reached, all roles for the node are automatically unchecked and the node is saved, thereby denying access to the form. This code is built on this post by quicksketch.

  // Count the number of submissions in the webform_submissions table for this node.
  $count = db_result(db_query("SELECT count(*) FROM {webform_submissions} WHERE nid = %d", $node->nid));

  // The submission limit is 20 - if it has been exceeded...
  if ($count >= 20) {
    // Uncheck all role access for this node. This disables access so users will see
    // this message when they navigate to the form: 'Submissions for this form are closed.'
    $node->webform['roles'] = array();
    
    // Save the node with all roles unchecked
    node_save($node);
  }

The next user that visits the form will receive the message "Submissions for this form are now closed.", which is the default behavior of Webform when no roles have access to submit the form.

Help improve this page

Page status: Not set

You can: