'How to position output of gravity forms dynamic output?

I'm simply trying to use the value from a Gravity Forms dynamically populated URL parameter as the ID for getting a custom field from Advanced Custom Fields. Using it like this returns the result within the of the content.

What is the best way to hook this such that it appears below the form. I've tried inserting the filter into the page template itself to no avail.

<?php
add_filter('gform_field_value_subclass', 'my_custom_population_function');
function my_custom_population_function($value)
{

    $repair = get_field('repair', $value);
    $report = get_field('report', $value);

    if ($repair && $report) : ?>

        <section class="rrr">
            <div class="row">

                <div class="repair">
                    <div class="r-wrap">
                        <h2 class="bracket-heading"><span>Step 2:</span>Report</h2>
                        <?php echo $repair ?>
                    </div>
                </div>

                <div class="recognize">
                    <div class="r-wrap">
                        <h2 class="bracket-heading"><span>Step 1:</span>Immediate Action Steps</h2>
                        <?php echo $report; ?>
                    </div>
                </div>
            </div>
        </section>

    <?php endif;

} ?>


Solution 1:[1]

I actually realized that something didn't feel right after looking over the first 20 pages of Google and not seeing a reference to this use case. The filters in Gravity Forms are more suited towards dynamic population of other fields, not to set context for the site as a whole. At least that's what it appears.

I found the better solution to be using query_vars.

In functions.php, I made it so that the URL parameter called subclass can be queried from Wordpress itself.

<?php
// add `author_more` to query vars
add_filter( 'init', 'add_subclass_query_var' );
function add_subclass_query_var()
{
    global $wp;
    $wp->add_query_var( 'subclass' );
}
?>

And then in my page template file, I grab that value that I need to set the ID of the field from the URL using get_query_var().

The rest is pretty straightforward and just prints the field values out where I need them.

<?php

$value = get_query_var('subclass');
$repair = get_field('repair', $value);
$report = get_field('report', $value);

if ($repair && $report) : ?>
    <section class="rrr">
        <div class="row">

            <div class="repair">
                <div class="r-wrap">
                    <h2 class="bracket-heading"><span>Step 2:</span>Report</h2>
                    <?php echo $repair ?>
                </div>
            </div>

            <div class="recognize">
                <div class="r-wrap">
                    <h2 class="bracket-heading"><span>Step 1:</span>Immediate Action Steps</h2>
                    <?php echo $report; ?>
                </div>
            </div>
        </div>
    </section>

<?php else:
    echo "No Results Found"
    ?>

<?php endif; ?>

https://codex.wordpress.org/WordPress_Query_Vars

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jon