4

I have a form in one of my templates

 <form method="post" action="" accept-charset="UTF-8">
    <input type="hidden" name="action" value="paypalPayments/payment/pay">

     [...] 
 </form>

I also created a simple plugin like so:

//PaypalPaymentsPlugin.php
 <?php 
 namespace Craft;
 class PaypalPaymentsPlugin extends BasePlugin {

    function getName() {
       return Craft::t('Paypal Payments');
     }

     function getVersion() {
       return '1.0';
     }

     function getDeveloper() {
       return 'Paul Timoce';
     }

     function getDeveloperUrl() {
       return "http://paultimoce.net";
     }
 }

And also a controller file inside a controller folder:

 //File PaypalPayments_PaymentController.php
 <?php 

   namespace Craft;

   class PaypalPayments_PaymentController extends BaseController {

     public function actionPayWithPaypal() 
     {
        echo "I'm in...";
     }
   }

All I want to do is post some variables through my form and process them with my plugin controller but every time I submit my form I hit the 404 page...

Do you guys have any idea as to why this is happening? I also installed and activated the sample cocktailRecipes plugin trying to do the same thing but unsuccessfully also... I tried to point my browser to /actions/paypalPayments/payment/pay and /actions/cocktailRecipes/ingredients/saveIngredient but also no luck... I always get redirected to the 404 page.

Can you help?

7

There's alot of different things that could be going on here.

First, if your action is named actionPayWithPaypal (as in the code above) the action url should be paypalPayments/payment/payWithPaypal I guess?

You won't be able to hit the cocktail recipes method directly from your browser since it requires the request to be a post. But you should be able to hit your controller with yourdomain.com/actions/paypalPayments/payment/payWithPaypal.

But, only if you're logged in. If you're not logged in, that will give you a 404 unless you enable anonymous access to the controller, see the documentation on how to do that.

Also, is your .htaccess rewriting working as it should? If not, that could cause problems with calling the action directly.

Try generating an action url and see if that works:

<a href="{{ actionUrl('paypalPayments/payment/payWithPaypal') }}">Test me</a>
| improve this answer | |
  • Thank you... the problem was that anonymous access was not granted to the controller... It now works fine! – Paul Timoce Sep 17 '14 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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