Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Gravity Forms - Tally Common Questions in Merge Tag
<?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 . "&nbsp;&nbsp;&nbsp;&nbsp;" . $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