Answers.Body: <p>When you set the <code>lastEntry</code> variable on your page. You are either setting <code>lastEntry</code> to be the <code>SproutForms_FormEntryModel</code> or <code>null</code>. In both cases you are defining the variable.</p>
  
  <pre><code>{# Sets lastEntry to SproutForms_FormEntryModel or null #}
  {% set lastEntry = craft.sproutForms.lastEntry() %}
  </code></pre>
  
  <p>If you then want to test the <code>lastEntry</code> variable, you'll need to use something different that <code>is defined</code>.</p>
  
  <p>I believe the following will work:</p>
  
  <pre><code>{% set lastEntry = craft.sproutForms.lastEntry() %}
  {% set qualified = true %}
  {% if lastEntry and lastEntry.fieldName == 'no' %}
      {% set qualified = false %}
  {% endif %}
  </code></pre>
  
  <p>Testing for <code>if lastEntry</code> will work just like using <code>if lastEntry is not null</code>. The secondary part of your conditional should only be evaluated if <code>if lastEntry</code> returns true, in which case your <code>SproutForms_FormEntryModel</code> would exist and the <code>fieldName</code> field would be defined, with or without a value.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-09T15:08:32.317Z
Answers.LastActivityDate: 2016-08-09T15:08:32.317Z
Answers.UserDisplayName: Ben Parizek
Body: <p>I'm trying to create a confirmation page for a Sprout form, where I want to check if a certain field is present, and if so, check for a value, so I can return a message based on that value.</p>
  
  <p>I'm using lastEntry, and am able to pull the valid fields in without a problem, but it's having issues checking whether the field is defined. I'm currently using the following code:</p>
  
  <pre><code>{% set lastEntry = craft.sproutForms.lastEntry() %}
  {% set qualified = true %}
  {% if lastEntry.fieldName is defined and lastEntry.fieldName == 'no' %}
      {% set qualified = false %}
  {% endif %}
  </code></pre>
  
  <p>When I use the code above, and the field has not been used in the particular form, I see:
  <code>Craft\SproutForms_EntryModel and its behaviors do not have a method or closure named "fieldName".</code></p>
  
  <p>It appears Craft is seeing the field as defined, but not. Anyone have any ideas on what I could do to figure this out?</p>
  
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-05T15:09:52.540Z
Comments.Text: The check for `is defined` should not be necessary. The `lastEntry` tag returns a `SproutForms_Entry` model which would define all fields that you have in your Form.  Also, your `is defined` check above could potentially return false positives in some scenarios. When you need to check `is defined` on Element attributes you'll want to use the syntax `if lastEntry['fieldName'] is defined`. (More on that issue in the Objects section here: https://straightupcraft.com/articles/how-to-check-if-a-variable-or-value-exists-using-twig).
Comments.UserDisplayName: Ben Parizek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-05T15:10:29.010Z
Comments.Text: Can you share what field type you are using in your example?
Comments.UserDisplayName: Ben Parizek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-08T17:12:29.260Z
Comments.Text: Aha. That's interesting. I'm using a drop-down field in this example.
Comments.UserDisplayName: Adam Ladrach
Tags: <plugin-sproutforms>
Title: Sprout Forms Confirmation Page Field Not Defined
ThreadText: # Sprout Forms Confirmation Page Field Not Defined
  
  (Asked by: username_0 on 2016-08-05)
  
  I'm trying to create a confirmation page for a Sprout form, where I want to check if a certain field is present, and if so, check for a value, so I can return a message based on that value.
  
  I'm using lastEntry, and am able to pull the valid fields in without a problem, but it's having issues checking whether the field is defined. I'm currently using the following code:
  
  ```
  {% set lastEntry = craft.sproutForms.lastEntry() %}
  {% set qualified = true %}
  {% if lastEntry.fieldName is defined and lastEntry.fieldName == 'no' %}
      {% set qualified = false %}
  {% endif %}
  
  ```
  
  When I use the code above, and the field has not been used in the particular form, I see:
  `Craft\SproutForms_EntryModel and its behaviors do not have a method or closure named "fieldName".`
  
  It appears Craft is seeing the field as defined, but not. Anyone have any ideas on what I could do to figure this out?
  
  Thanks!
  
  **Tags:** plugin-sproutforms
  
  > **Comments:**
  > **username_1**: The check for `is defined` should not be necessary. The `lastEntry` tag returns a `SproutForms_Entry` model which would define all fields that you have in your Form.  Also, your `is defined` check above could potentially return false positives in some scenarios. When you need to check `is defined` on Element attributes you'll want to use the syntax `if lastEntry['fieldName'] is defined`. (More on that issue in the Objects section here: https://straightupcraft.com/articles/how-to-check-if-a-variable-or-value-exists-using-twig).  
  > **username_1**: Can you share what field type you are using in your example?  
  > **username_0**: Aha. That's interesting. I'm using a drop-down field in this example.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-09. Score: 0 | Accepted answer
  
  When you set the `lastEntry` variable on your page. You are either setting `lastEntry` to be the `SproutForms_FormEntryModel` or `null`. In both cases you are defining the variable.
  
  ```
  {# Sets lastEntry to SproutForms_FormEntryModel or null #}
  {% set lastEntry = craft.sproutForms.lastEntry() %}
  
  ```
  
  If you then want to test the `lastEntry` variable, you'll need to use something different that `is defined`.
  
  I believe the following will work:
  
  ```
  {% set lastEntry = craft.sproutForms.lastEntry() %}
  {% set qualified = true %}
  {% if lastEntry and lastEntry.fieldName == 'no' %}
      {% set qualified = false %}
  {% endif %}
  
  ```
  
  Testing for `if lastEntry` will work just like using `if lastEntry is not null`. The secondary part of your conditional should only be evaluated if `if lastEntry` returns true, in which case your `SproutForms_FormEntryModel` would exist and the `fieldName` field would be defined, with or without a value.
  
  
  ---
  
  