Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spivurno/8c1ae35c51ad61f6da0a709dcc73d395 to your computer and use it in GitHub Desktop.
Save spivurno/8c1ae35c51ad61f6da0a709dcc73d395 to your computer and use it in GitHub Desktop.
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