Created
May 7, 2018 10:57
-
-
Save Idealien/f601602db1cdd66c0133c890724a1328 to your computer and use it in GitHub Desktop.
Gravity Flow - User Input Validation to prevent step completion without certain data
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
<?php | |
add_filter( 'gravityflow_validation_user_input', 'step_complete_data_check', 10, 3 ); | |
add_filter( 'gravityflow_validation_user_input', 'step_inprogress_bypass_required', 10, 3 ); | |
function step_complete_data_check( $validation_result, $step, $new_status ) { | |
if( ($validation_result['form']['id'] == "121" && rgpost( 'step_id' ) == 40 && $new_status == 'in_progress') ) { | |
foreach( $form['fields'] as &$field ) { | |
if ( $field->id == 16 ) { | |
//Check for the value you want to prevent without here | |
$validation_result['is_valid'] = false; | |
$field->failed_validation = true; | |
$field->validation_message = 'You must have X in order to complete the step'; | |
break; | |
} | |
} | |
} | |
$validation_result['form'] = $form; | |
} | |
return $validation_result; | |
} | |
function step_inprogress_bypass_required( $validation_result, $step, $new_status ) { | |
if( ($validation_result['form']['id'] == "121" && rgpost( 'step_id' ) == 40 && $new_status == 'in_progress') ) { | |
$form = $validation_result['form']; | |
foreach ( $form['fields'] as &$field ) { | |
$field->failed_validation = false; | |
$field->validation_message = ''; | |
} | |
$validation_result = array( | |
'is_valid' => true, | |
'form' => $form, | |
); | |
} | |
return $validation_result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment