Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Last active August 31, 2022 11:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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' );
}
} );
@wemakefuture
Copy link

made my day thanks!

@Maks1983
Copy link

im soory for the newb question, but where do i put this code? inside themes functions.php? or somewhere else?

@slaFFik
Copy link
Author

slaFFik commented Nov 21, 2020

@Maks1983, here is a blog article that has all the details about where and how to put a code snippet to make it work: https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/
Please note, this code snippet works only with a paid version of the WPForms plugin because entries storage is available only from the Basic license (not available in WPForms Lite).

You can also consider upgrading to WPForms Pro to get access to Form Locker addon with a lot more features, as well as many others addons. Also, the Black Friday deal is coming ;)

@Maks1983
Copy link

@slaFFik, thank you very much. Love you

@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