Last active
August 29, 2015 14:07
-
-
Save Sjouw/bae40f6eda74b17fd478 to your computer and use it in GitHub Desktop.
Quickscan with redirect to resultpage (using Gravity Forms)
This file contains hidden or 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
/** | |
* 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; | |
} |
This file contains hidden or 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
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