Skip to content

Instantly share code, notes, and snippets.

@Sjouw
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sjouw/bae40f6eda74b17fd478 to your computer and use it in GitHub Desktop.
Save Sjouw/bae40f6eda74b17fd478 to your computer and use it in GitHub Desktop.
Quickscan with redirect to resultpage (using Gravity Forms)
/**
* We calculate the input value of give form inputs and change the redirect url afterwards
*
* @param array $form, array $lead
*
* @return array $confirmation[ 'redirect' ]
**/
add_filter( 'gform_confirmation', 'custom_confirmation', 10, 4 );
function custom_confirmation($confirmation, $form, $lead, $ajax){
// replace the 'id' value with the ID of your used Gravity Form
if( $form[ 'id' ] == '2' ){
$count = 0;
$total_count = 0;
foreach( $lead as $key => $value ):
if( is_numeric( $key ) ):
// replace 'Ja' with the value that needs to be counted (checkbox)
if( 'Ja' == $value ):
$count++;
endif;
$total_count++;
endif;
endforeach;
$percentage = ( $count / $total_count ) * 100;
// if more than 40% of the questions is answered with the needed answer, then redirect to... (replace percentage with you own value)
if( $percentage >= 40 ):
// redirect to the page selected in the given ACF Option
$confirmation = array( 'redirect' => get_field('option1', 'option') );
else:
// redirect to the page selected in the given ACF Option
$confirmation = array( 'redirect' => get_field('option1', 'option') );
endif;
}
return $confirmation;
}
if( function_exists('acf_add_options_sub_page') ){
// Add new ACF Options subpage where you can select the pages for the redirects
acf_add_options_sub_page( 'Quickscan' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment