Skip to content

Instantly share code, notes, and snippets.

@reachkamrul
Created June 12, 2020 09:37
Show Gist options
  • Save reachkamrul/f6a9033eebf50c9734f4ac8170307c63 to your computer and use it in GitHub Desktop.
Save reachkamrul/f6a9033eebf50c9734f4ac8170307c63 to your computer and use it in GitHub Desktop.
//Restrict repeated submission by user per day based on IP
add_action('fluentform_before_insert_submission', function ( $insertData, $data, $formId ) {
if($formId != 6) { // You can pass your form id here
return;
}
// IP based check
$last24Hours = date('Y-m-d H:i:s', time() - 24 * 60 * 60);
$isExist = wpFluent()->table('fluentform_submissions')
->where('form_id', $formId)
->where('ip', $insertData['ip'])
->where('created_at', '>', date('Y-m-d').' 00:00:00')
->first();
if($isExist) {
wp_send_json(['errors' => [
'restricted' => [
'Sorry! You can not submit twice in a day. Try again tomorrow'
]
]], 422);
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment