2

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 }}">
    </form>

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);
}
1

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

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.