Answers.Body: <p>Make sure you are <a href="https://www.php.net/manual/en/language.namespaces.importing.php" rel="nofollow noreferrer">importing</a> the <code>SproutForms</code> base class into your php file. The code below assumes you'd be using the namespace of your actual custom module and class:</p>
  <pre><code>&lt;?php
  namespace modules/mycustommodule;
  
  use barrelstrength\sproutforms\SproutForms;
  
  class MyCustomClass
  {
    public function myCustomMethod()
    {
      $formHandle = 'my-form-handle';
      $form = SproutForms::$app-&gt;forms-&gt;getFormByHandle($formHandle);
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-17T07:34:27.487Z
Answers.LastActivityDate: 2021-07-17T07:34:27.487Z
Answers.UserDisplayName: Ben Parizek
Answers.Body: <p>The error indicates that <code>SproutForms::$app</code> is not an object, which would mean it has not been initialized yet. If you look at the source code, you can see that <code>SproutForms::$app</code> is a <a href="https://github.com/barrelstrength/craft-sprout-forms/blob/3475f142ea6d89b8b60f55cb53043a0923a6a03e/src/SproutForms.php#L91-L96" rel="nofollow noreferrer">static property on the SproutForms class</a> that starts out undefined. It's only assigned the current <code>App</code> instance once it's <a href="https://github.com/barrelstrength/craft-sprout-forms/blob/3475f142ea6d89b8b60f55cb53043a0923a6a03e/src/SproutForms.php#L136-L140" rel="nofollow noreferrer">init method has been executed</a>. The static property access (<code>SproutForms::$app</code>) doesn't instantiate the app, so if the plugin hasn't been instantiated yet you could get this error.</p>
  <p>You can probably solve this by requesting an instance of the SproutForms plugin using the <a href="https://docs.craftcms.com/api/v3/craft-services-plugins.html#method-getplugin" rel="nofollow noreferrer">Plugins service</a> manually to ensure it gets initialized properly before accessing it's <code>$app</code> property:</p>
  <pre class="lang-php prettyprint-override"><code>$SproutForms = \Craft::$app-&gt;plugins-&gt;getPlugin('sprout-forms');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-16T17:34:26.960Z
Answers.Text: Thank you so much for this suggestion! I am just learning how to work with oop php and this is really helpful.
Answers.UserDisplayName: JJefferyDev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-16T07:56:43.657Z
Answers.LastActivityDate: 2021-07-16T07:56:43.657Z
Answers.UserDisplayName: MoritzLost
Body: <p>I need to reference specific entries from my Sprout Form so that I can grab the data the user uploaded through that form to use to make changes in the database.  I am stuck here with this error message: &quot;Trying to get property 'forms' of non-object&quot;.</p>
  <pre><code>$appFormHandle = 'formHandle';
  $appForm = SproutForms::$app-&gt;forms-&gt;getFormByHandle($appFormHandle);
  
  $appEntry = SproutForms::$app-&gt;entries-&gt;getEntry($appForm);
  echo $appEntry-&gt;entryId;
  </code></pre>
  <p>How do I properly reference the form so I can get the data from its entries to use in a plugin?</p>
  
Tags: <craft3><plugin-sproutforms><sprout>
Title: How to reference a specific Sprout Form by handle?
ThreadText: # How to reference a specific Sprout Form by handle?
  
  (Asked by: username_0 on 2021-07-16)
  
  I need to reference specific entries from my Sprout Form so that I can grab the data the user uploaded through that form to use to make changes in the database. I am stuck here with this error message: "Trying to get property 'forms' of non-object".
  
  ```
  $appFormHandle = 'formHandle';
  $appForm = SproutForms::$app->forms->getFormByHandle($appFormHandle);
  
  $appEntry = SproutForms::$app->entries->getEntry($appForm);
  echo $appEntry->entryId;
  
  ```
  
  How do I properly reference the form so I can get the data from its entries to use in a plugin?
  
  **Tags:** craft3, plugin-sproutforms, sprout
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-07-17. Score: 1
  
  Make sure you are [importing](https://www.php.net/manual/en/language.namespaces.importing.php) the `SproutForms` base class into your php file. The code below assumes you'd be using the namespace of your actual custom module and class:
  
  ```
  <?php
  namespace modules/mycustommodule;
  
  use barrelstrength\sproutforms\SproutForms;
  
  class MyCustomClass
  {
    public function myCustomMethod()
    {
      $formHandle = 'my-form-handle';
      $form = SproutForms::$app->forms->getFormByHandle($formHandle);
    }
  }
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2021-07-16. Score: 1
  
  The error indicates that `SproutForms::$app` is not an object, which would mean it has not been initialized yet. If you look at the source code, you can see that `SproutForms::$app` is a [static property on the SproutForms class](https://github.com/barrelstrength/craft-sprout-forms/blob/3475f142ea6d89b8b60f55cb53043a0923a6a03e/src/SproutForms.php#L91-L96) that starts out undefined. It's only assigned the current `App` instance once it's [init method has been executed](https://github.com/barrelstrength/craft-sprout-forms/blob/3475f142ea6d89b8b60f55cb53043a0923a6a03e/src/SproutForms.php#L136-L140). The static property access (`SproutForms::$app`) doesn't instantiate the app, so if the plugin hasn't been instantiated yet you could get this error.
  
  You can probably solve this by requesting an instance of the SproutForms plugin using the [Plugins service](https://docs.craftcms.com/api/v3/craft-services-plugins.html#method-getplugin) manually to ensure it gets initialized properly before accessing it's `$app` property:
  
  ```php
  $SproutForms = \Craft::$app->plugins->getPlugin('sprout-forms');
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you so much for this suggestion! I am just learning how to work with oop php and this is really helpful.  
  
  ---
  
  