Skip to content

Instantly share code, notes, and snippets.

@Idealien
Created May 7, 2018 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Idealien/f601602db1cdd66c0133c890724a1328 to your computer and use it in GitHub Desktop.
Save Idealien/f601602db1cdd66c0133c890724a1328 to your computer and use it in GitHub Desktop.
Gravity Flow - User Input Validation to prevent step completion without certain data
<?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