<p>You can use <a href="https://craftcms.com/classreference/services/HttpRequestService#getPost-detail" rel="nofollow noreferrer"><code>craft()-&gt;request-&gt;getPost('name')</code></a> to grab any posted values from your form submission.</p>

CC BY-SA 3.0
2017-04-22T04:09:57.233Z
2017-04-22T04:09:57.233Z
Brad Bell
<p>If you are using <strong>Craft 3</strong>, then use <a href="https://docs.craftcms.com/api/v3/craft-web-twig-variables-request.html#method-getparam" rel="nofollow noreferrer">getParam()</a> at your controller action:</p>
<pre><code>$request = Craft::$app-&gt;getRequest();
</code></pre>
<p>with this you get all the posted data with one request, then you use what you need like this:</p>
<pre><code>$name= $request-&gt;getParam(&quot;formInput&quot;);
</code></pre>
<p>where <strong>&quot;formInput&quot;</strong> is the input field name attribute:</p>
<pre><code>&lt;input type=&quot;text&quot; name=&quot;formInput&quot;&gt;
</code></pre>

CC BY-SA 4.0
2021-12-15T12:24:26.153Z
2021-12-15T12:24:26.153Z
Ra3d K
<p>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?</p>

<p>Twig template file:</p>

<pre><code>&lt;form method="post" action="" accept-charset="UTF-8"&gt;

&lt;input type="hidden" name="action" value="psychEmail/publication/pubRequest"&gt;
        &lt;input type="text" name="theemailaddress" value="" size="100"&gt;

        &lt;!-- ...--&gt;

        &lt;input class="btn submit" type="submit" value="{{ 'Submit'|t }}"&gt;
    &lt;/form&gt;
</code></pre>

<p>function IN controller:</p>

<pre><code>public function actionPubRequest()
{
    $this-&gt;requirePostRequest();

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

    craft()-&gt;email-&gt;sendEmail($email);
}
</code></pre>

<plugin-development>
How to reference Twig form values from within controller action?
# How to reference Twig form values from within controller action?

(Asked by: username_0 on 2017-04-22)

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:



        

        

        
    

function IN controller:
public function actionPubRequest()
{
    $this->requirePostRequest();

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

    craft()->email->sendEmail($email);
}

**Tags:** plugin-development

---

## 2 answers

### Answer by username_1 on 2017-04-22. Score: 2 | Accepted answer

You can use [`craft()->request->getPost('name')`](https://craftcms.com/classreference/services/HttpRequestService#getPost-detail) to grab any posted values from your form submission.


---

### Answer by username_2 on 2021-12-15. Score: 1

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:


---

