Answers.Body: <p>Does the request requires login?<br>
  If it doesn't, you need to add the exception on the controller<br>
  <code>protected $allowAnonymous = array('actionSubscribe');</code></p>
  
  <p>Also, did you try adding <strong>admin</strong> to your URL?<br>
  <code>&lt;input type="hidden" name="action" value="/admin/actions/paypalSubscription/subscription/subscribe"&gt;</code></p>
  
  <p>I was trying to post to an action once through the front-end and it only worked after adding <strong>/admin</strong></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-25T22:40:43.030Z
Answers.LastActivityDate: 2015-03-25T22:40:43.030Z
Answers.UserDisplayName: Marlon Marcello
Answers.Body: <p><strike>Possible that it's just that the first is singular the second is plural.</strike></p>
  
  <p><strong>Update</strong>
  Perhaps the problem is on your form side then. If you're posting from a form, you do not need 'action' as part of the url. Also might check that you have <code>method="post"</code> attribute defined.</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
      {{ getCsrfInput() }}
      &lt;input type="hidden" name="action" value="paypalSubscription/subscription/subscribe"&gt;
      &lt;input type="hidden" name="redirect" value="subscription-complete"&gt;
      ...
  &lt;/form&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-26T08:45:57.220Z
Answers.Text: Updated answer with another possibility.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-26T09:23:27.763Z
Answers.Text: This seems more plausible. However, when I use the form like this, the POST request is made to the same page. meaning it re-renders the form and does nothing. Maybe this is because my template doesn't use the base templates and such. I'm having trouble getting that to work, but that can be for another question I guess.
Answers.UserDisplayName: Ryan Merl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-26T14:10:37.533Z
Answers.Text: I have no idea if it makes a difference, but what happens if you add the `action` as an attribute to the <form> tag, instead of a hidden input field? I.e. `<form method="post" action="paypalSubscription/subscription/subscribe">`
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-26T14:13:54.730Z
Answers.Text: ...or you might have some routes messing things up?
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-26T16:57:52.543Z
Answers.Text: Putting `action` on the form itself then posts to `/actions/paypalSubscriptions/subscription/paypalSubscriptions/subscription/subscribe`
Answers.UserDisplayName: Ryan Merl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-26T18:43:26.543Z
Answers.Text: What do you mean by "not using the base templates"? Are you not extending `_layouts/cp`? If so, that shouldn't really make any difference, in my experience.
  
  Are you positive you don't have any conflicting routes set up in `PaypalSubscriptionPlugin.php`? I can't see any issues with your controller + the form Douglas McDonald pasted, so if those don't work together I'm thinking there's something else tripping you up.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T03:29:50.480Z
Answers.Text: I don't have any routes defined in my plugin.
Answers.UserDisplayName: Ryan Merl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T04:42:13.040Z
Answers.Text: When you use `name="action"` and then omit 'action' in the uri, you are saying that it's re-rendering the same page. It's possible that it's returning an error and that you are not capturing it. You might try printing out all the errors. See [one of the sample forms](http://buildwithcraft.com/docs/templating/user-registration-form) in the docs for an example of how to display errors. You might also just print to your plugins log file from the controller to see if it's getting hit at all.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-27T04:51:11.893Z
Answers.Text: You can log to your plugin's log file using `PaypalSubscriptionPlugin::log('Form submitted.', LogLevel::Info);` or just throw an exception — `throw new Exception(craft::t("Form submitted"));`
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-26T07:07:03.783Z
Answers.LastActivityDate: 2015-02-26T09:06:49.570Z
Answers.LastEditDate: 2015-02-26T09:06:49.570Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I'm working on a plugin to do subscription billing with paypal. I have the following controller</p>
  
  <pre><code>class PaypalSubscription_SubscriptionController extends BaseController {
  
      public function actionSubscriptions() {
          // This renders a form that collects some info on subscription options
      }
  
      public function actionSubscribe() {
          $this-&gt;requirePostRequest();
          // This takes data and starts a paypal transaction
      }
  }
  </code></pre>
  
  <p>I can get to the form by going to <code>/actions/paypalSubscription/subscription/subscriptions</code></p>
  
  <p>I've tried hard coding the url <code>/actions/paypalSubscription/subscription/subscribe</code> as well as using <code>actionUrl('/paypalSubscription/subscription/subscribe')</code>. The <code>actionUrl</code> call prepends <code>index.php/actions</code> to the string which is just incorrect, and either way both approaches 404. What am I missing here?</p>
  
  <p>I know that i'm logged in and that works correctly since I can reach the original form and anonymous access shouldn't be turned on, so I don't believe that's the issue.</p>
  
Tags: <plugin-development><controller>
Title: Trouble posting to plugin controller
ThreadText: # Trouble posting to plugin controller
  
  (Asked by: username_0 on 2015-02-26)
  
  I'm working on a plugin to do subscription billing with paypal. I have the following controller
  
  ```
  class PaypalSubscription_SubscriptionController extends BaseController {
  
      public function actionSubscriptions() {
          // This renders a form that collects some info on subscription options
      }
  
      public function actionSubscribe() {
          $this->requirePostRequest();
          // This takes data and starts a paypal transaction
      }
  }
  
  ```
  
  I can get to the form by going to `/actions/paypalSubscription/subscription/subscriptions`
  
  I've tried hard coding the url `/actions/paypalSubscription/subscription/subscribe` as well as using `actionUrl('/paypalSubscription/subscription/subscribe')`. The `actionUrl` call prepends `index.php/actions` to the string which is just incorrect, and either way both approaches 404. What am I missing here?
  
  I know that i'm logged in and that works correctly since I can reach the original form and anonymous access shouldn't be turned on, so I don't believe that's the issue.
  
  **Tags:** plugin-development, controller
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-03-25. Score: 3
  
  Does the request requires login?  
  If it doesn't, you need to add the exception on the controller  
  `protected $allowAnonymous = array('actionSubscribe');`
  
  Also, did you try adding **admin** to your URL?  
  `<input type="hidden" name="action" value="/admin/actions/paypalSubscription/subscription/subscribe">`
  
  I was trying to post to an action once through the front-end and it only worked after adding **/admin**
  
  
  ---
  
  ### Answer by username_2 on 2015-02-26. Score: 1
  
  Possible that it's just that the first is singular the second is plural.
  
  **Update**
  Perhaps the problem is on your form side then. If you're posting from a form, you do not need 'action' as part of the url. Also might check that you have `method="post"` attribute defined.
  
  ```
  <form method="post" accept-charset="UTF-8">
      {{ getCsrfInput() }}
      <input type="hidden" name="action" value="paypalSubscription/subscription/subscribe">
      <input type="hidden" name="redirect" value="subscription-complete">
      ...
  </form>
  
  ```
  
  > **Comments:**
  > **username_2**: Updated answer with another possibility.  
  > **username_0**: This seems more plausible. However, when I use the form like this, the POST request is made to the same page. meaning it re-renders the form and does nothing. Maybe this is because my template doesn't use the base templates and such. I'm having trouble getting that to work, but that can be for another question I guess.  
  > **username_3**: I have no idea if it makes a difference, but what happens if you add the `action` as an attribute to the <form> tag, instead of a hidden input field? I.e. `<form method="post" action="paypalSubscription/subscription/subscribe">`  
  > **username_3**: ...or you might have some routes messing things up?  
  > **username_0**: Putting `action` on the form itself then posts to `/actions/paypalSubscriptions/subscription/paypalSubscriptions/subscription/subscribe`  
  > **username_3**: What do you mean by "not using the base templates"? Are you not extending `_layouts/cp`? If so, that shouldn't really make any difference, in my experience.  Are you positive you don't have any conflicting routes set up in `PaypalSubscriptionPlugin.php`? I can't see any issues with your controller + the form username_2 pasted, so if those don't work together I'm thinking there's something else tripping you up.  
  > **username_0**: I don't have any routes defined in my plugin.  
  > **username_2**: When you use `name="action"` and then omit 'action' in the uri, you are saying that it's re-rendering the same page. It's possible that it's returning an error and that you are not capturing it. You might try printing out all the errors. See [one of the sample forms](http://buildwithcraft.com/docs/templating/user-registration-form) in the docs for an example of how to display errors. You might also just print to your plugins log file from the controller to see if it's getting hit at all.  
  > **username_2**: You can log to your plugin's log file using `PaypalSubscriptionPlugin::log('Form submitted.', LogLevel::Info);` or just throw an exception — `throw new Exception(craft::t("Form submitted"));`  
  
  ---
  
  