Last active Oct 27, 2017
Gravity Perks // GP Limit Choices // Prevent Concurrent Submissions from Consuming the Last Choice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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