Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gravity Perks // GP Limit Choices // Prevent Concurrent Submissions from Consuming the Last Choice
/**
* Gravity Perks // GP Limit Choices // Prevent Concurrent Submissions from Consuming the Last Choice
* http://gravitywiz.com/documentation/gravity-forms-limit-choices/
*/
add_action( 'gform_validation', 'gplc_lock', 99 );
function gplc_lock ( $result ) {
$is_last_page = GFFormDisplay::get_target_page( $result['form'], GFFormDisplay::get_source_page( $result['form']['id'] ), rgpost( 'gform_field_values' ) ) == '0';
$lock = new GP_Lock( 'gplc-lock' );
if ( $result['is_valid'] && $is_last_page && ! $lock->lock() ) {
$result['is_valid'] = false;
add_filter( 'gform_validation_message', function( $message ) {
return "<div class='validation_error'>There was a problem processing your submission. Please resubmit the form.</div>";
} );
}
return $result;
}
add_action( 'gform_entry_created', function() {
$lock = new GP_Lock( 'gplc-lock' );
$lock->unlock();
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.