Last active
October 27, 2017 16:17
-
-
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
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