<p><strong>TL;DR</strong><br>
This issue has been resolved and will be available in the next release of <a href="http://sprout.barrelstrengthdesign.com/craft-plugins/forms" rel="nofollow">Sprout Forms</a> (0.8.4)</p>

<p>The issue was caused by our use of <code>context switching</code> for custom content tables in combination with <code>renderObjectTemplate()</code>, the latter of which initializes the <code>twig environment</code> and loads globals if not already loaded. This initialization is <code>context sensitive</code> so since we needed to switch context and then use <code>renderObjectTemplate()</code> before we could switch the <code>context</code> back, <code>globals</code> would inherit the content model from the form entry itself, not their actual content.</p>

<p>We fixed this issue by initializing the environment before any context switching is done.</p>

<p><a href="http://selv.in" rel="nofollow">Selvin Ortiz</a><br>
<strong>Barrel Strength Design</strong></p>

CC BY-SA 3.0
2015-01-09T21:03:53.380Z
2015-01-09T21:03:53.380Z
Selvin Ortiz
<p>I'm using global fields on a multi language site to get the appropriate content depending on the locales used. Sof far so good.</p>

<p>However on a form page (sproutforms) these globals empty out after the form is submitted while an (input) error occurred.</p>

<p>How to overcome this issue?</p>

<pre><code>                {# FORM #}
            &lt;section class="col-sm-6 col-md-6" style="padding-bottom: 40px;"&gt;

            {# Prepare our error macro #}
            {% macro errorList(errors) %}
                {# To display errors, you want to make sure errors exist, and then you can loop through and display them #}
                {% if errors %}
                    {% for error in errors %}
                        {{ error }}&lt;/br&gt;
                    {% endfor %}
                {% endif %}
            {% endmacro %}

            {% from _self import errorList %}


            {# Check if we should display or form or thank you message #}
            {% if craft.request.getParam('message') == ('thank-you' or 'bedankt-voor-uw-aanvraag') %}

                {# Check for the last entry submitted #}
                {% set lastEntry = craft.sproutForms.lastEntry() %}

                {% if lastEntry %}

                    {# If the last entry exists, we can output any of the variables that were present in the form submission. #}

                    &lt;div class="alert fade in"&gt;
                        &lt;i class="fa fa-cloud-download alert-icon"&gt;&lt;/i&gt;
                        &lt;button type="button" class="close" data-dismiss="alert"&gt;×&lt;/button&gt;
                        &lt;p&gt;Thanks &lt;strong&gt;{{ lastEntry.fullName }}&lt;/strong&gt;! We'll be in touch soon! Did you know you can display any of the values that were submitted in the form?  Here's a list of all the values in the last form submission:&lt;/p&gt;
                    &lt;/div&gt;


                {% endif %}

            {% else %}

                &lt;form id="contactform" class="form-box register-form contact-form" method="post" accept-charset="utf-8"&gt;
                    {{ getCsrfInput() }}
                    &lt;input type="hidden" name="action" value="sproutForms/entries/saveEntry"&gt;
                    &lt;input type="hidden" name="handle" value="contact"&gt;
                    {% if craft.locale == 'en_us' %}
                    &lt;input type="hidden" name="redirect" value="/en/contact?message=thank-you"&gt;
                    {% endif %}
                    {% if craft.locale == 'nl_nl' %}
                    &lt;input type="hidden" name="redirect" value="/contact?message=bedankt-voor-uw-aanvraag"&gt;
                    {% endif %}

                    &lt;h3 class="title"&gt;{{ formsAndButtons.contact }}&lt;/h3&gt;
                    &lt;div id="success"&gt;&lt;/div&gt;

                    &lt;label class="control-label" &gt;{{ formsAndButtons.yourName }} &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
                    &lt;input class="form-control"  type="text" id="textName" name="fields[fullName]" {%- if contact is defined %}value="{{ contact.fullName }}"{% endif -%}&gt;
                    {% if contact is defined %}
                    &lt;div class="error"&gt;
                        {{ errorList(contact.getErrors('fullName')) }}
                    &lt;/div&gt;
                    {% endif %}

                    &lt;label&gt;{{ formsAndButtons.email }} &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
                    &lt;input class="form-control" type="email" id="textEmail" name="fields[email]" {%- if contact is defined %}value="{{ contact.email }}"{% endif -%}&gt;
                    {% if contact is defined %}
                    &lt;div class="error"&gt;
                        {{ errorList(contact.getErrors('email')) }}
                    &lt;/div&gt;
                    {% endif %}

                    &lt;label&gt;{{ formsAndButtons.telephone }} &lt;/label&gt;
                    &lt;input class="form-control"  type="text" id="textPhone" name="fields[phone]" {%- if contact is defined %}value="{{ contact.phone }}"{% endif -%}&gt;
                    {% if contact is defined %}
                    &lt;div class="error"&gt;
                        {{ errorList(contact.getErrors('phone')) }}
                    &lt;/div&gt;
                    {% endif %}

                    &lt;label&gt;{{ formsAndButtons.comment }} &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
                    &lt;textarea class="form-control" id="fields-message" name="fields[message]"&gt;{%- if contact is defined %}{{ contact.message }}{% endif -%}&lt;/textarea&gt;
                    {% if contact is defined %}
                    &lt;div class="error"&gt;
                        {{ errorList(contact.getErrors('message')) }}
                    &lt;/div&gt;
                    {% endif %}

                    &lt;div class="clearfix"&gt;&lt;/div&gt;

                    &lt;div class="buttons-box clearfix"&gt;
                        &lt;input class="btn btn-default" type="submit" value="{{ login.submit }}"&gt;
                        &lt;span class="required"&gt;&lt;b&gt;*&lt;/b&gt; {{ login.requiredField }}&lt;/span&gt;
                    &lt;/div&gt;
                &lt;/form&gt;

            {% endif %}
            &lt;/section&gt;
</code></pre>

CC BY-SA 3.0
2015-01-08T19:04:20.100Z
Sounds like a Sprout Forms bug to me, no? Have you tried contacting them?
Brad Bell
<form><globals><plugin-sproutforms>
Globals fields empty after form errors
# Globals fields empty after form errors

(Asked by: username_0 on 2015-01-08)

I'm using global fields on a multi language site to get the appropriate content depending on the locales used. Sof far so good.
However on a form page (sproutforms) these globals empty out after the form is submitted while an (input) error occurred.
How to overcome this issue?
                {# FORM #}
            

            {# Prepare our error macro #}
            {% macro errorList(errors) %}
                {# To display errors, you want to make sure errors exist, and then you can loop through and display them #}
                {% if errors %}
                    {% for error in errors %}
                        {{ error }}
                    {% endfor %}
                {% endif %}
            {% endmacro %}

            {% from _self import errorList %}


            {# Check if we should display or form or thank you message #}
            {% if craft.request.getParam('message') == ('thank-you' or 'bedankt-voor-uw-aanvraag') %}

                {# Check for the last entry submitted #}
                {% set lastEntry = craft.sproutForms.lastEntry() %}

                {% if lastEntry %}

                    {# If the last entry exists, we can output any of the variables that were present in the form submission. #}

                    
                        
                        ×
                        Thanks {{ lastEntry.fullName }}! We'll be in touch soon! Did you know you can display any of the values that were submitted in the form?  Here's a list of all the values in the last form submission:
                    


                {% endif %}

            {% else %}

                
                    {{ getCsrfInput() }}
                    
                    
                    {% if craft.locale == 'en_us' %}
                    
                    {% endif %}
                    {% if craft.locale == 'nl_nl' %}
                    
                    {% endif %}

                    {{ formsAndButtons.contact }}
                    

                    {{ formsAndButtons.yourName }} *
                    
                    {% if contact is defined %}
                    
                        {{ errorList(contact.getErrors('fullName')) }}
                    
                    {% endif %}

                    {{ formsAndButtons.email }} *
                    
                    {% if contact is defined %}
                    
                        {{ errorList(contact.getErrors('email')) }}
                    
                    {% endif %}

                    {{ formsAndButtons.telephone }} 
                    
                    {% if contact is defined %}
                    
                        {{ errorList(contact.getErrors('phone')) }}
                    
                    {% endif %}

                    {{ formsAndButtons.comment }} *
                    {%- if contact is defined %}{{ contact.message }}{% endif -%}
                    {% if contact is defined %}
                    
                        {{ errorList(contact.getErrors('message')) }}
                    
                    {% endif %}

                    

                    
                        
                        * {{ login.requiredField }}
                    
                

            {% endif %}

**Tags:** form, globals, plugin-sproutforms

> **Comments:**
> **username_1**: Sounds like a Sprout Forms bug to me, no? Have you tried contacting them?  

---

## 1 answers

### Answer by username_2 on 2015-01-09. Score: 2

**TL;DR**  
This issue has been resolved and will be available in the next release of [Sprout Forms](http://sprout.barrelstrengthdesign.com/craft-plugins/forms) (0.8.4)

The issue was caused by our use of `context switching` for custom content tables in combination with `renderObjectTemplate()`, the latter of which initializes the `twig environment` and loads globals if not already loaded. This initialization is `context sensitive` so since we needed to switch context and then use `renderObjectTemplate()` before we could switch the `context` back, `globals` would inherit the content model from the form entry itself, not their actual content.

We fixed this issue by initializing the environment before any context switching is done.

[username_2](http://selv.in)  
**Barrel Strength Design**


---

