Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.