Limit Webform Submission to one per quarter per user I need to limit one webform submission per quarter. For each quarter, the user can only make one submission. I want to use one webform. Here are some examples of the date period and the due date. How can I achieve the desired outcome with Webforms?


Q1 (Oct. 1, 2019 – Dec. 30, 2019): due by Jan. 15, 2020
Q2 (Jan. 1, 2020 – Mar. 30, 2020): due by Apr. 15, 2020
Q3 (Apr. 1, 2020 – Jun. 30, 2020): due by Jul. 15, 2020
ok so here is how to do that.. you need to create a module and set Drupal cron to run once a day on your hosting provider
then you need your webform to have email unique then do this ....  

/**
 * Implements hook_cron().
 */
function YOURMODULE_cron() {
  $current_month = date('m');
  // Get first month of quarter
  $new_month = (3 * floor(($current_month - 1 ) / 3)) + 1;
  $new_month = substr('0' . $new_month, -2);
  $first_quarter_day_date = date('Y') . '-' . $new_month . '-01';
  $today = date('Y-m-d');
  // So this is the first day of the quarter.
  if ($first_quarter_day_date == $today) {
    // Use cache to make sure this runs once.
    $cid = 'clear_out_webform_date';
    $cached = \Drupal::cache()-&gt;get($cid);
    $run = TRUE;
    if (!empty($cached)) {
      if (!empty($cached-&gt;data['date'])) {
        if ($cached-&gt;data['date'] == $today) {
          $run = FALSE;
        }
      }
    }

    if ($run == TRUE) {
      // change this to your webform id
      $webform_id = 'contact';

      // Export all submissions to file.
      $webform = \Drupal\webform\Entity\Webform::load($webform_id);
      $submission_exporter = \Drupal::service('webform_submission.exporter');
      $export_options = $submission_exporter-&gt;getDefaultExportOptions();
      $export_options['delimiter'] = ';';
      $export_options['multiple_delimiter'] = ',';
      $submission_exporter-&gt;setWebform($webform);
      $submission_exporter-&gt;setExporter($export_options);
      $submission_exporter-&gt;generate();
      $file_path = $submission_exporter-&gt;getExportFilePath();
      // rename the file to something good.
      $filename = $today.'-export.csv';
      $uri = 'public://' . $filename;
      $fileContent = file_get_contents($file_path);
      $destination = $uri;
      // Save the file to be a file entity.
      $file = file_save_data(
        $fileContent,
        $destination,
        FILE_EXISTS_RENAME
      );
      if (is_object($file)) {
        // Probably email your self a reminder here.
        // ^^ file is now an entity so you can do something like.
        // load a know entity and append the file to a document field.
        // or just download it as in the public file dir.

        // Delete previous quarter submissions.
        $query = \Drupal::entityQuery('webform_submission')
          -&gt;condition('webform_id', $webform_id);
        $result = $query-&gt;execute();
        if (!empty($result)) {
          $webform_submission_storage = \Drupal::entityTypeManager()-&gt;getStorage('webform_submission');
          $submissions = $webform_submission_storage-&gt;loadMultiple($result);
          foreach ($submissions as $submission) {
            $submission-&gt;delete();
          }
        }
      }
      // set the cache to today so it wont run again.
      \Drupal::cache()-&gt;set($cid, ['date' =&gt; $today]);
    }
  }
}


have fun and good luck.