1

Has anyone experience with the ContactFormRequiredFields plugin? It works fine until the send button is pressed. It brings up an "Undefined variable: formEntry" error. When I look into the plugin I see that "formEntry" is connected to "formId". But what goes wrong?

        ...

        $formId = craft()->request->getPost('formId');
        $formId = craft()->security->validateData($formId);

        /**
         * Get the form entry using the ID
         */
        if ($formId)
        {
            $formEntry = craft()->entries->getEntryById($formId);
        }

        ...

Stack trace:

#0  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/etc/web/WebApp.php(693): CApplication->handleError(8, "Undefined variable: formEntry", "/var/www/vhosts/tonartmusikschule.at/httpdocs/craft/plugins/cont...", 
#1  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/plugins/contactformrequiredfields/ContactFormRequiredFieldsPlugin.php(48): Craft\WebApp->handleError(8, "Undefined variable: formEntry", "/var/www/vhosts/tonartmusikschule.at/httpdocs/craft/plugins/cont...", 48, ...)
#2  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/base/CComponent.php(567): Craft\ContactFormRequiredFieldsPlugin->Craft\{closure}(Craft\ContactFormEvent)
#3  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/plugins/contactform/services/ContactFormService.php(73): CComponent->raiseEvent("onbeforesend", Craft\ContactFormEvent)
#4  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/plugins/contactform/controllers/ContactFormController.php(139): Craft\ContactFormService->onBeforeSend(Craft\ContactFormEvent)
#5  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/actions/CInlineAction.php(49): Craft\ContactFormController->actionSendMessage()
#6  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(array("p" => "anmeldung_index"))
#7  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CController.php(286): CController->runAction(CInlineAction)
#8  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array())
#9  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CWebApplication.php(282): CController->run("sendMessage")
#10 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/etc/web/WebApp.php(836): CWebApplication->runController("contactForm/sendMessage")
#11 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/etc/web/WebApp.php(287): Craft\WebApp->_processActionRequest()
#12 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#13 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/index.php(62): CApplication->run()
#14 /var/www/vhosts/tonartmusikschule.at/httpdocs/public/index.php(19): require_once("/var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/index.ph...")
2

The plugin expects the the ID of the entry you are using to build the form fields to be submitted along with the form so it is available as a request variable.

You should include the ID of the entry you are using to build the form’s fields when you are submitting to the contactForm/sendMessage controller. For example:

{% set form = craft.entries({
    section: 'forms',
    slug: 'contact-form',
}).first() %}

<form method="post" accept-charset="UTF-8">
    <input type="hidden" name="action" value="contactForm/sendMessage">
    <input type="hidden" name="formId" value="{{ form.id|hash }}" />
    ...
    {# Loop through the form fields here #}
    <button type="submit">Send</button>
</form>

The code above assumes you have a section with the handle forms and the slug of the entry you want is contact-form.

If you want a more robust solution that provides the form builder and validation out of the box, you might consider checking out Freeform from Solspace.

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.