2

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.

2 Answers 2

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

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>
9
  • Updated answer with another possibility. Commented Feb 26, 2015 at 8:45
  • 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.
    – Ryan Merl
    Commented Feb 26, 2015 at 9:23
  • 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"> Commented Feb 26, 2015 at 14:10
  • 1
    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 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. Commented Feb 27, 2015 at 4:42
  • 1
    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")); Commented Feb 27, 2015 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.