CF7下拉菜单限制数量

时间:2021-04-08 15:41:25

标签: javascript wordpress plugins conditional-statements contact-form-7

我正在尝试构建一个允许用户选择学校日期的联系表单,我想限制提交的数量,以免超额预订课程。我通常每周提供一节课,每节课最多有 12 个座位。我一直在到处搜索,但找不到将下拉菜单中的选择限制为仅允许提交 12 次的方法。因此,例如,如果在下拉列表中我的下一堂课是 4 月 9 日,一旦提交了该表格并选择了 4 月 9 日 12 次,我需要将 4 月 9 日变灰并且不再可选。我尝试了多个预订日历插件,但它们对于这个简单的任务来说都太复杂了,或者不够复杂,我真的很喜欢我现有的联系表格 7 已经工作的方式,因为它是唯一允许签名字段的表格之一。我只需要能够在联系表格中限制对一个特定问题的选择。任何帮助将不胜感激。

我目前使用的是智能网格布局,这是我插入到functions.php文件中的代码

    add_filter( 
'cf7sg_dynamic_dropdown_custom_options','dayClass_dynamic_options',10,3);

function dayClass_dynamic_options($options, $name, $cf7_key){
  if('training-school-application_copy'!==$cf7_key || 'dayClass' !== $name){
    return $options;
  } 

  $data = array (
    'April 16th - 17th' => "val1",
    'May 21st - 22nd' => "val2",
    'June 18th - 19th' => "val3",
    'July 16th - 17th' => "val4",
  );

    $options='<option value="">Select a Date</option>'.PHP_EOL;
    foreach($data as $label=>$value){
      $options .= '<option value="'.$value.'">'.$label.'</option>'.PHP_EOL;
    }
  return $options;
}

add_filter( 
'cf7sg_dynamic_dropdown_custom_options','recert_dynamic_options',10,3);

function recert_dynamic_options($options, $name, $cf7_key){
  if('training-school-application_copy'!==$cf7_key || 'recert' !== $name){
    return $options;
  } 

  $data2 = array (
    'April 6th' => "val1",
    'May 4th' => "val2",
    'June 1st' => "val3",
    'July 6th' => "val4",
  );

    $options='<option value="">Select a Date</option>'.PHP_EOL;
    foreach($data2 as $label=>$value){
      $options .= '<option value="'.$value.'">'.$label.'</option>'.PHP_EOL;
    }
  return $options;
}

add_filter( 
'cf7sg_dynamic_dropdown_custom_options','combo_dynamic_options',10,3);

function combo_dynamic_options($options, $name, $cf7_key){
  if('training-school-application_copy'!==$cf7_key || 'combo' !== $name){
    return $options;
  } 

  $data3 = array (
    'April 14th - 17th' => "val1",
    'May 19th - 22nd' => "val2",
    'June 16th - 19th' => "val3",
    'July 14th - 17th' => "val4",
  );

    $options='<option value="">Select a Date</option>'.PHP_EOL;
    foreach($data3 as $label=>$value){
      $options .= '<option value="'.$value.'">'.$label.'</option>'.PHP_EOL;
    }
  return $options;
}

然后我将此代码插入到联系表单中,我使用条件字段根据表单中上一个问题的选择显示相应的组

 <div class="halfWidth">
 [group dayClass][dynamic_select custom-list1 class:select2 "source:filter"] 
 [/group]
 [group recert][dynamic_select custom-list2 class:select2 "source:filter"] 
 [/group]
 [group combo][dynamic_select custom-list3 class:select2 "source:filter"] 
 [/group]
 </div>

我不知道如何将选项限制为每个选项最多 12 个选项?有人可以告诉我如何在提交 12 次后限制和隐藏日期值吗?

0 个答案:

没有答案