Php 如何在特定日期内防止表格中的重复条目
我正在努力防止我的两张重力表出现重复条目。我只需要在特定的时间范围内,根据特定的字段(如“电子邮件”或“地址”)阻止这些条目。因此,如果他们在Php 如何在特定日期内防止表格中的重复条目,php,wordpress,gravity-forms-plugin,gravityforms,Php,Wordpress,Gravity Forms Plugin,Gravityforms,我正在努力防止我的两张重力表出现重复条目。我只需要在特定的时间范围内,根据特定的字段(如“电子邮件”或“地址”)阻止这些条目。因此,如果他们在开始日期之前有相同“电子邮件”的条目,他们仍然可以提交表格而不会发出任何问题。如果他们在开始日期之后和结束日期之前有相同“电子邮件”的条目,则他们将无法提交表格。下面的代码是我目前拥有的,但它不起作用。非常感谢您的帮助 add_filter( 'gform_is_duplicate', 'custom_duplicate_entry_rules', 10,
开始日期
之前有相同“电子邮件”的条目,他们仍然可以提交表格而不会发出任何问题。如果他们在开始日期
之后和结束日期
之前有相同“电子邮件”的条目,则他们将无法提交表格。下面的代码是我目前拥有的,但它不起作用。非常感谢您的帮助
add_filter( 'gform_is_duplicate', 'custom_duplicate_entry_rules', 10, 4 );
function custom_duplicate_entry_rules( $count, $form_id, $field, $value ) {
$form_id = array( 6,61 );
$search_criteria = array(
'start_date' => 2021-02-01, // Get entries from date after last event
'end_date' => 2022-01-20, // Up to right before next event
'field_filters' => array( // which fields to search
array(
'key' => 'email',
)
)
);
$search_past_entries = GFAPI::count_entries($form_id, $search_criteria);
if ( $search_past_entries >= '1' ) {
echo 'You have already signed up.';
}
}
我设法在一位开发人员的帮助下解决了这个问题
add_filter( 'gform_is_duplicate_6', 'custom_duplicate_entry_rules', 10, 4 );
add_filter( 'gform_is_duplicate_61', 'custom_duplicate_entry_rules', 10, 4 );
function custom_duplicate_entry_rules( $count, $form_id, $field, $value ) {
$search_criteria = array(
'start_date' => '2021-02-01', // Get entries from date after last event
'end_date' => '2022-01-20', // Up to right before next event
'field_filters' => array( // which fields to search
array(
'key' => 2,
'value' => $value,
)
)
);
$count = GFAPI::count_entries( $form_id, $search_criteria );
if( $count >= 1 ) {
return $count;
} else {
return 0;
}
}
我需要在field_filters
中的特定条目meta上加上点,在本例中,对于电子邮件地址(这是重力表单中的字段ID),该条目最终为2。最后,我将if语句更改为返回$count
或0。除此之外,重力还起着所有的作用