Answers.Body: <p>You can just grab whatever you need either from <code>$_POST</code> or, more preferably, <a href="http://buildwithcraft.com/classreference/services/HttpRequestService#getPost-detail" rel="nofollow">craft()->request->getPost()</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T21:16:31.227Z
Answers.Text: ...and if you want to get a specific variable, you can do ```craft()->request->getPost('invoiceSku')```.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-12T20:56:10.160Z
Answers.LastActivityDate: 2015-10-12T20:56:10.160Z
Answers.UserDisplayName: Brad Bell
Body: <p>My users have an accountBalance field and there's a createInvoice service in my plugin. I'd like to autogenerate an invoice whenever the accountBalance changes (including from the admin cp), while optionally passing in extra invoice info. Is there a way to access the raw post data from the event to check for extra info like invoice skus and descriptions?</p>
  
  <p>In my plugin I have the following code.</p>
  
  <pre><code>craft()-&gt;on('users.onBeforeSaveUser', function(Event $event)
  {
      $userId = $event-&gt;params['user']-&gt;id;
      $user = craft()-&gt;users-&gt;getUserById($userId);
  
      //raw post data is private so these lines are pseudo code
      if ($extraPostData != null)
      {
          $desc = $event-&gt;params['_rawPostData']['invoiceDescription'];
          $sku = $event-&gt;params['_rawPostData']['invoiceSku'];
      }
  
      $oldBalance = $user-&gt;accountBalance;
      $newBalance = $event-&gt;params['user']-&gt;accountBalance;
      if ($newBalance != $oldBalance)
      {
          $balanceDelta = $newBalance - $oldBalance;
  
          //plugin service has defaults if $desc/$sku are empty or null
          craft()-&gt;myPlugin-&gt;createInvoice($balanceDelta, $userId, $desc, $sku);
      }
  }
  </code></pre>
  
  <p>Alternatively, is there a way to disable adjusting the accountBalance user field from the admin cp?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-12T20:04:52.763Z
Comments.Text: Not sure I'm following 100%, but could you just pull them from `$_POST`? (or `craft()->request->getPost()`)?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-12T20:49:50.123Z
Comments.Text: Derp, yah that works. Didn't think  $_POST would be available from within the event. Time for more coffee. Thanks for the answer.
Comments.UserDisplayName: David Rampersad
Tags: <plugin-development><users><events>
Title: Accessing the raw post data from an $event
ThreadText: # Accessing the raw post data from an $event
  
  (Asked by: username_0 on 2015-10-12)
  
  My users have an accountBalance field and there's a createInvoice service in my plugin. I'd like to autogenerate an invoice whenever the accountBalance changes (including from the admin cp), while optionally passing in extra invoice info. Is there a way to access the raw post data from the event to check for extra info like invoice skus and descriptions?
  
  In my plugin I have the following code.
  
  ```
  craft()->on('users.onBeforeSaveUser', function(Event $event)
  {
      $userId = $event->params['user']->id;
      $user = craft()->users->getUserById($userId);
  
      //raw post data is private so these lines are pseudo code
      if ($extraPostData != null)
      {
          $desc = $event->params['_rawPostData']['invoiceDescription'];
          $sku = $event->params['_rawPostData']['invoiceSku'];
      }
  
      $oldBalance = $user->accountBalance;
      $newBalance = $event->params['user']->accountBalance;
      if ($newBalance != $oldBalance)
      {
          $balanceDelta = $newBalance - $oldBalance;
  
          //plugin service has defaults if $desc/$sku are empty or null
          craft()->myPlugin->createInvoice($balanceDelta, $userId, $desc, $sku);
      }
  }
  
  ```
  
  Alternatively, is there a way to disable adjusting the accountBalance user field from the admin cp?
  
  **Tags:** plugin-development, users, events
  
  > **Comments:**
  > **username_1**: Not sure I'm following 100%, but could you just pull them from `$_POST`? (or `craft()->request->getPost()`)?  
  > **username_0**: Derp, yah that works. Didn't think  $_POST would be available from within the event. Time for more coffee. Thanks for the answer.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-10-12. Score: 2 | Accepted answer
  
  You can just grab whatever you need either from `$_POST` or, more preferably, [craft()->request->getPost()](http://buildwithcraft.com/classreference/services/HttpRequestService#getPost-detail).
  
  > **Comments:**
  > **username_2**: ...and if you want to get a specific variable, you can do ```craft()->request->getPost('invoiceSku')```.  
  
  ---
  
  