0

I'm working on a plugin and need a front-end (non CP) form that submits to one of the plugin controllers. Here's my setup:

- plugins
  - portal
    -- PortalPlugin.php
    - controller
      -- Portal_AccessController.php

Portal_AccessController.php

<?php
namespace Craft;

class Portal_AccessController extends BaseController {

    protected $allowAnonymous = true;

    public function actionLogin() {

        echo 'Here';

    }

}

I then created a front-end form by adding a new template directory in /craft/templates:

- pro-portal
  -- index.html

With index.html containing:

<form method="post" action="" accept-charset="UTF-8">
    <input type="hidden" name="action" value="portal/access/login">

    <div>
        <input type="text" maxlength="4">
        <input type="text" maxlength="4">
        <input type="text" maxlength="4">
        <input type="text" maxlength="4">
    </div>
    <a href="{{ actionUrl('portal/access/login') }}">Test me</a>
    <input class="btn submit" type="submit" value="Submit">
</form>

Hitting mydomain.com/pro-portal displays the form. On submit it returns to /pro-portal but with a 404 error.

I also tried creating an action link but that also results in a 404 at /index.php/actions/portal/access/login.

I've looked through answers on similar questions and tried all the solutions but no luck. Am I overlooking something? Missing something?

2
  • What's $response['redirect'] and where is it coming from?
    – Brad Bell
    Mar 5 '15 at 21:43
  • I tried passing in a redirect parameter to redirect to a new URL. That's not in my code at the moment. I've update the question to show that. Mar 5 '15 at 21:46
0

You're getting a 404 because your action method isn't telling Craft what do to after it has echo'd 'Here', so routing continues.

See #3 is that link:

The request doesn’t necessarily end after a controller has been called. The controller may allow it to keep going.

You can redirect, end the request, load up a template to display, etc.

Update:

The controller folder needs to be renamed to controllers.

5
  • So if I put something like $this->redirect('http://google.com'); in my controller method it should redirect, but I'm still being returned to /pro-portal and getting the 404 page. Mar 5 '15 at 21:56
  • If you put a die(); after the echo, do you see the text?
    – Brad Bell
    Mar 5 '15 at 22:09
  • No. I get the 404 page. Mar 5 '15 at 22:10
  • Oh, it's not even making it to the action then. Rename your controller folder to controllers.
    – Brad Bell
    Mar 5 '15 at 22:11
  • I knew it would be something simple like that. Thank you! Mar 5 '15 at 22:13

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.