Last active
December 11, 2017 08:10
-
-
Save Idealien/ca3a3e86ede360c3e2c1 to your computer and use it in GitHub Desktop.
Gravity Forms - Tally Common Questions in Merge Tag
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( 'gform_replace_merge_tags', array(&$this, "replace_tally_results"), 10, 7 ); | |
function replace_tally_results( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) { | |
$custom_merge_tag = '{tally_results}'; | |
if ( strpos( $text, $custom_merge_tag ) === false ) { | |
return $text; | |
} | |
$score = array(); | |
foreach($form['fields'] as $field) { | |
if( $field['type'] == "radio") { | |
if( isset( $score[ $entry[ $field['id'] ] ] ) ) { | |
$score[ $entry[ $field['id'] ] ] = $score[ $entry[ $field['id'] ] ] + 1; | |
} else { | |
$score[ $entry[ $field['id'] ] ] = 1; | |
} | |
} | |
} | |
$result = ""; | |
foreach($score as $key => $value) { | |
$result .= $value . " " . $key ."<br/>"; | |
} | |
$text = str_replace( $custom_merge_tag, $result, $text ); | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment