I have a form and a hidden action that successfully runs the controller action. I now want to include 2 variables (form input values) and then use those values while I am in the controller action. How do I grab the value (theemailaddress) that was in the form?

Twig template file:

<form method="post" action="" accept-charset="UTF-8">

<input type="hidden" name="action" value="psychEmail/publication/pubRequest">
        <input type="text" name="theemailaddress" value="" size="100">

        <!-- ...-->

        <input class="btn submit" type="submit" value="{{ 'Submit'|t }}">

function IN controller:

public function actionPubRequest()

    $email = new EmailModel();
    $email->fromEmail = 'email@school.edu';
    $email->toEmail = 'myemail@gmail.com';
    $email->subject = 'Publication Request';
    $email->body    = 'Your requested publication is attached.';


2 Answers 2


You can use craft()->request->getPost('name') to grab any posted values from your form submission.


If you are using Craft 3, then use getParam() at your controller action:

$request = Craft::$app->getRequest();

with this you get all the posted data with one request, then you use what you need like this:

$name= $request->getParam("formInput");

where "formInput" is the input field name attribute:

<input type="text" name="formInput">

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.