Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Last active August 31, 2022 11:32
Show Gist options
  • Save slaFFik/52af17ae7a524997647de432bd21f353 to your computer and use it in GitHub Desktop.
Save slaFFik/52af17ae7a524997647de432bd21f353 to your computer and use it in GitHub Desktop.
WPForms: Submit the form only once for logged in users.
<?php
add_action( 'wp', function () {
if ( ! is_user_logged_in() ) {
return;
}
$entries = wpforms()->entry->get_entries(
array(
'form_id' => 74, // CHANGE THIS FORM ID
'user_id' => get_current_user_id(),
),
true // count values only, we don't need actual data
);
// We allow to fill the form only once.
if ( $entries >= 1 ) {
add_action( 'wpforms_frontend_output_before', function () {
echo '<p>You have already submitted this form.</p>';
} );
add_action( 'wpforms_frontend_load', '__return_false' );
}
} );
@mahnad
Copy link

mahnad commented Aug 31, 2022

hi,
I tried this code in three wp code snippet plugins, but in all of them, one form can be sent multiple times.
please guide me.

@mahnad
Copy link

mahnad commented Aug 31, 2022

hi,

I tried this code in three wp code snippet plugins, but in all of them, one form can be sent multiple times. Or it locks other forms and does not allow sending other forms
please guide me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment