Answers.Body: <p>Where is your "craft()-on()" code located?</p>
  
  <p>Per the documentation, the best place is in your primary plugin file in a method named "init()".</p>
  
  <p><a href="https://craftcms.com/docs/plugins/hooks-and-events#listening-for-events" rel="nofollow noreferrer">https://craftcms.com/docs/plugins/hooks-and-events#listening-for-events</a></p>
  
  <p>For example, here's mine:</p>
  
  <pre><code>public function init()
  {
      parent::init();
  
      // event triggers
      craft()-&gt;on('charge.onValidate', array($this, '_validateRegistrationForm'));
      craft()-&gt;on('entries.saveEntry', array($this, '_processEditPricelistLocationForm'));
      craft()-&gt;on('entries.saveEntry', array($this, '_processEditGuestUsersForm'));
      craft()-&gt;on('entries.saveEntry', array($this, '_processGuestUserAccessForm'));
      craft()-&gt;on('entries.onBeforeSaveEntry', array($this, '_processEditGuestRemoveUsersForm'));
  }
  </code></pre>
  
  <p>and here's just showing that I do in fact handle the Event $event in the method:</p>
  
  <pre><code>/**
   * Charge onValidate
   *
   * @param Event $event
   */
  public function _validateRegistrationForm(Event $event)
  {
      // do stuff
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-09T06:35:29.517Z
Answers.LastActivityDate: 2017-03-09T06:35:29.517Z
Answers.UserDisplayName: Jarrett Barnett
Body: <p>I created my own <code>actionEntrySave</code> for my frontend form. and I'm using the<br> <code>$entryService-&gt;saveEntry($entry);</code> method to store my entries into the database.<br><br>The problem is this does not fire</p>
  
  <pre><code>craft()-&gt;on('entries.onSaveEntry', function(Event $event) {
      die(var_dump("fired"));
  });
  </code></pre>
  
  <p>When I save/edit the same entry in the backend or create a new one I see an empty page with "fired" there.. (just for testing) and I can manipulate the entry the way I want without any problems. If I do the same in the frontend (saving/editing an entry) the event does not trigger but the entry saves. Can someone explain why?</p>
  
  <p>Thank you very much</p>
  
  <p>edit: I already tried onBeforeSaveEntry with the same result</p>
  
  <p><strong>Edit 2 Solved</strong>
  <br>I solved it now.. my error was I did this</p>
  
  <pre><code>$entryService = new EntriesService();
  $dbInsert = $entryService-&gt;saveEntry($entry);
  </code></pre>
  
  <p>But it has to look like </p>
  
  <pre><code>$entryService = craft()-&gt;entries;
  $dbInsert = $entryService-&gt;saveEntry($entry);
  </code></pre>
  
  <p>I thought all services were singletons. My mistake</p>
  
Tags: <plugin-development><entries><events>
Title: entries.onSaveEntry does not fire from frontend
ThreadText: # entries.onSaveEntry does not fire from frontend
  
  (Asked by: username_0 on 2017-03-08)
  
  I created my own `actionEntrySave` for my frontend form. and I'm using the  
   `$entryService->saveEntry($entry);` method to store my entries into the database.  
    
  The problem is this does not fire
  
  ```
  craft()->on('entries.onSaveEntry', function(Event $event) {
      die(var_dump("fired"));
  });
  
  ```
  
  When I save/edit the same entry in the backend or create a new one I see an empty page with "fired" there.. (just for testing) and I can manipulate the entry the way I want without any problems. If I do the same in the frontend (saving/editing an entry) the event does not trigger but the entry saves. Can someone explain why?
  
  Thank you very much
  
  edit: I already tried onBeforeSaveEntry with the same result
  
  **Edit 2 Solved**
    
  I solved it now.. my error was I did this
  
  ```
  $entryService = new EntriesService();
  $dbInsert = $entryService->saveEntry($entry);
  
  ```
  
  But it has to look like
  
  ```
  $entryService = craft()->entries;
  $dbInsert = $entryService->saveEntry($entry);
  
  ```
  
  I thought all services were singletons. My mistake
  
  **Tags:** plugin-development, entries, events
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-09. Score: 2
  
  Where is your "craft()-on()" code located?
  
  Per the documentation, the best place is in your primary plugin file in a method named "init()".
  
  <https://craftcms.com/docs/plugins/hooks-and-events#listening-for-events>
  
  For example, here's mine:
  
  ```
  public function init()
  {
      parent::init();
  
      // event triggers
      craft()->on('charge.onValidate', array($this, '_validateRegistrationForm'));
      craft()->on('entries.saveEntry', array($this, '_processEditPricelistLocationForm'));
      craft()->on('entries.saveEntry', array($this, '_processEditGuestUsersForm'));
      craft()->on('entries.saveEntry', array($this, '_processGuestUserAccessForm'));
      craft()->on('entries.onBeforeSaveEntry', array($this, '_processEditGuestRemoveUsersForm'));
  }
  
  ```
  
  and here's just showing that I do in fact handle the Event $event in the method:
  
  ```
  /**
   * Charge onValidate
   *
   * @param Event $event
   */
  public function _validateRegistrationForm(Event $event)
  {
      // do stuff
  }
  
  ```
  
  
  ---
  
  