1

I'm very new to craft and I'm having trouble finding an answer to my question (I've scoured the questions on here - but the only answers appear to be for plugins).

Basically, I want to submit a form to an action in a controller - which will be inside a Module.

I have this form in a template:

<form method="post" action="" accept-charset="UTF-8"> <input type="hidden" name="action" value="site/say"> <input class="btn submit" type="submit" value="submit me"> </form>

I'm trying to get it to go to this controller (which is in modules/controllers/SiteController):

<?php

namespace app\controllers;

use yii\web\Controller;

class SiteController extends Controller
{
    // ...existing code...

    public function actionSay($message = 'Hello')
    {
        die('in say action');
    }
}

I'm constantly getting a 404 - I've tried different variations for the value of action, e.g. actions/site/say. Do I need to add a route somewhere like in Laravel? Really, really stuck on this, any help would be appreciated.

2

You need to include your module handle to the route

module-handle/site/say

You also should use the correct namespace instead of app/controllers I suggest you to read the documentation

You can as well define a route if you like

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.