One Fluent Forms Submission per Logged-In User
Lets each logged-in member submit the Fluent Forms forms you choose only once, which suits surveys, votes and applications, with a clear message on a second attempt.
Opens WPIDE on
Code
$wpide_ff_once_forms = array(); // Form IDs, e.g. array( 1 ).
$wpide_ff_once_message = 'You have already submitted this form. Thank you!';
add_filter( 'fluentform/validation_errors', function ( $errors, $data, $form ) use ( $wpide_ff_once_forms, $wpide_ff_once_message ) {
if ( is_user_logged_in() && in_array( (int) $form->id, array_map( 'intval', $wpide_ff_once_forms ), true ) && get_user_meta( get_current_user_id(), '_wpide_ff_done_' . (int) $form->id, true ) ) {
$errors['_wpide_once'] = array( $wpide_ff_once_message );
}
return $errors;
}, 10, 3 );
add_action( 'fluentform/submission_inserted', function ( $entry_id, $data, $form ) use ( $wpide_ff_once_forms ) {
if ( is_user_logged_in() && in_array( (int) $form->id, array_map( 'intval', $wpide_ff_once_forms ), true ) ) {
update_user_meta( get_current_user_id(), '_wpide_ff_done_' . (int) $form->id, time() );
}
}, 10, 3 );
Notes
List the form IDs at the top; submissions are remembered in user meta and logged-out visitors are not limited.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.