Answers.Body: <p>When leveraging another plugin programmatically, you will typically want to use the service layer. In your case, the <code>SproutForms_EntriesService.php</code> is where the <code>saveEntry</code> action gets processed. The <code>saveEntry</code> service method expects a <code>SproutForms_EntryModel</code>:</p>
  
  <pre><code>craft()-&gt;sproutForms-&gt;saveEntry($entry);
  </code></pre>
  
  <p>Here is a longer example:</p>
  
  <pre><code>// Create a new instance of a SproutForms_EntryModel
  $entry = new SproutForms_EntryModel();
  
  // Set some SproutForms_EntryModel attributes
  $entry-&gt;formId    = 4051;
  $entry-&gt;ipAddress = '127.0.0.1';
  $entry-&gt;userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36';
  
  // Set the custom fields
  $entry-&gt;setContentFromPost(array(
      'fullName' =&gt; 'Test Name',
      'message' =&gt; 'Test message'
  ));
  
  // Save the entry
  craft()-&gt;sproutForms_entries-&gt;saveEntry($entry);
  </code></pre>
  
  <p>Sprout Forms should dynamically set the title value for you, based on the value you have in the <code>Advanced-&gt;Title Format</code> setting.</p>
  
  <p>In the case it doesn't seem to work, a quick way to see if there are any errors is to kill your script after you tried to save the entry and view the full list of errors (or use a more advanced <a href="https://straightupcraft.com/events/troubleshooting-and-debugging-errors-in-php" rel="nofollow noreferrer">PHP debugging workflow</a> with a tool like XDebug):</p>
  
  <pre><code>Craft::dd($entry-&gt;getErrors());
  </code></pre>
  
  <p>See the answer from Brandon Kelly on this post for more information on how to <a href="https://craftcms.stackexchange.com/questions/4486/what-is-getcontent-the-contentmodel-and-how-do-i-use-it-to-get-and-set-cust">set custom fields on an Element</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-04T22:02:02.170Z
Answers.Text: Thank you for the comprehensive answer Ben :) fantastic. I'll give it a try and mark it as correct then.
Answers.UserDisplayName: JamesNZ
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-30T04:54:34.830Z
Answers.LastActivityDate: 2016-12-06T07:17:11.463Z
Answers.LastEditDate: 2017-04-13T12:51:00.200Z
Answers.UserDisplayName: Ben Parizek
Body: <p>I'd like to be able to create a Sprout Forms entry from another plugin I'm working on. Is this possible?</p>
  
  <p>I had a bit of a look at the <strong>SproutForms_EntriesController->actionSaveEntry()</strong> action but it's kind of all bundled up.</p>
  
  <p>This other plugin is a self contained booking system that I don't want to use an actual Sprout Forms form for - but to keep it consistent for the client I'd like to write (for reference) these entries into a pre-existing form I've set up.</p>
  
  <p>Thanks!</p>
  
Tags: <plugin-sproutforms>
Title: Write into Sprout Forms from another plugin
ThreadText: # Write into Sprout Forms from another plugin
  
  (Asked by: username_0 on 2016-11-30)
  
  I'd like to be able to create a Sprout Forms entry from another plugin I'm working on. Is this possible?
  
  I had a bit of a look at the **SproutForms\_EntriesController->actionSaveEntry()** action but it's kind of all bundled up.
  
  This other plugin is a self contained booking system that I don't want to use an actual Sprout Forms form for - but to keep it consistent for the client I'd like to write (for reference) these entries into a pre-existing form I've set up.
  
  Thanks!
  
  **Tags:** plugin-sproutforms
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-30. Score: 3 | Accepted answer
  
  When leveraging another plugin programmatically, you will typically want to use the service layer. In your case, the `SproutForms_EntriesService.php` is where the `saveEntry` action gets processed. The `saveEntry` service method expects a `SproutForms_EntryModel`:
  
  ```
  craft()->sproutForms->saveEntry($entry);
  
  ```
  
  Here is a longer example:
  
  ```
  // Create a new instance of a SproutForms_EntryModel
  $entry = new SproutForms_EntryModel();
  
  // Set some SproutForms_EntryModel attributes
  $entry->formId    = 4051;
  $entry->ipAddress = '127.0.0.1';
  $entry->userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36';
  
  // Set the custom fields
  $entry->setContentFromPost(array(
      'fullName' => 'Test Name',
      'message' => 'Test message'
  ));
  
  // Save the entry
  craft()->sproutForms_entries->saveEntry($entry);
  
  ```
  
  Sprout Forms should dynamically set the title value for you, based on the value you have in the `Advanced->Title Format` setting.
  
  In the case it doesn't seem to work, a quick way to see if there are any errors is to kill your script after you tried to save the entry and view the full list of errors (or use a more advanced [PHP debugging workflow](https://straightupcraft.com/events/troubleshooting-and-debugging-errors-in-php) with a tool like XDebug):
  
  ```
  Craft::dd($entry->getErrors());
  
  ```
  
  See the answer from Brandon Kelly on this post for more information on how to [set custom fields on an Element](https://craftcms.stackexchange.com/questions/4486/what-is-getcontent-the-contentmodel-and-how-do-i-use-it-to-get-and-set-cust).
  
  > **Comments:**
  > **username_0**: Thank you for the comprehensive answer Ben :) fantastic. I'll give it a try and mark it as correct then.  
  
  ---
  
  