Answers.Body: <p>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. </p>
  
  <p>You should include the ID of the entry you are using to build the form’s fields when you are submitting to the <code>contactForm/sendMessage</code> controller. For example:</p>
  
  <pre><code>{% set form = craft.entries({
      section: 'forms',
      slug: 'contact-form',
  }).first() %}
  
  &lt;form method="post" accept-charset="UTF-8"&gt;
      &lt;input type="hidden" name="action" value="contactForm/sendMessage"&gt;
      &lt;input type="hidden" name="formId" value="{{ form.id|hash }}" /&gt;
      ...
      {# Loop through the form fields here #}
      &lt;button type="submit"&gt;Send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The code above assumes you have a section with the handle <em>forms</em> and the slug of the entry you want is <em>contact-form</em>.</p>
  
  <p>If you want a more robust solution that provides the form builder and validation out of the box, you might consider checking out <a href="https://solspace.com/craft/freeform" rel="nofollow noreferrer">Freeform</a> from Solspace.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-14T16:59:57.307Z
Answers.LastActivityDate: 2018-02-14T16:59:57.307Z
Answers.UserDisplayName: Stephen Bowling
Body: <p>Has anyone experience with the <a href="https://github.com/Studiosaurus/contactformrequiredfields" rel="nofollow noreferrer">ContactFormRequiredFields</a> 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?</p>
  
  <pre><code>        ...
  
          $formId = craft()-&gt;request-&gt;getPost('formId');
          $formId = craft()-&gt;security-&gt;validateData($formId);
  
          /**
           * Get the form entry using the ID
           */
          if ($formId)
          {
              $formEntry = craft()-&gt;entries-&gt;getEntryById($formId);
          }
  
          ...
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>#0  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/etc/web/WebApp.php(693): CApplication-&gt;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-&gt;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-&gt;Craft\{closure}(Craft\ContactFormEvent)
  #3  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/plugins/contactform/services/ContactFormService.php(73): CComponent-&gt;raiseEvent("onbeforesend", Craft\ContactFormEvent)
  #4  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/plugins/contactform/controllers/ContactFormController.php(139): Craft\ContactFormService-&gt;onBeforeSend(Craft\ContactFormEvent)
  #5  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/actions/CInlineAction.php(49): Craft\ContactFormController-&gt;actionSendMessage()
  #6  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CController.php(308): CInlineAction-&gt;runWithParams(array("p" =&gt; "anmeldung_index"))
  #7  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CController.php(286): CController-&gt;runAction(CInlineAction)
  #8  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CController.php(265): CController-&gt;runActionWithFilters(CInlineAction, array())
  #9  /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/web/CWebApplication.php(282): CController-&gt;run("sendMessage")
  #10 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/etc/web/WebApp.php(836): CWebApplication-&gt;runController("contactForm/sendMessage")
  #11 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/etc/web/WebApp.php(287): Craft\WebApp-&gt;_processActionRequest()
  #12 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/framework/base/CApplication.php(185): Craft\WebApp-&gt;processRequest()
  #13 /var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/index.php(62): CApplication-&gt;run()
  #14 /var/www/vhosts/tonartmusikschule.at/httpdocs/public/index.php(19): require_once("/var/www/vhosts/tonartmusikschule.at/httpdocs/craft/app/index.ph...")
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-09T18:10:45.757Z
Comments.Text: I'm not familiar with a "Contact Form Required Fields" plugin and I'm not seeing it on https://straightupcraft.com/craft-plugins/. Is it something you've custom written?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-10T16:01:48.953Z
Comments.Text: It is by Stephen Bowling who wrote a handy instruction for dynamic contact form code with the contactform plugin. http://stephenbowling.com/blog/2016/05/13/native-email-forms-in-craft-cms. 
  The plugin: https://github.com/Studiosaurus/contactformrequiredfields
Comments.UserDisplayName: analog junkie
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-11T17:07:36.467Z
Comments.Text: Can you enable devMode and share the stack trace leading up to that error?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-12T09:48:51.957Z
Comments.Text: Stack trace is now added.
Comments.UserDisplayName: analog junkie
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-12T21:57:45.000Z
Comments.Text: Guessing you're just missing this part from the [docs](https://github.com/Studiosaurus/contactformrequiredfields#using-contact-form-required-fields)?  "The entry’s id must be included in the posted variables as formId and hashed."
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-13T13:30:05.497Z
Comments.Text: @BradBell: How do I hash an Id? I tried it with {{ formId|hash }} but that wasn't the solution. I am a bit clueless here, how to use the formId so the plugin can read it.
Comments.UserDisplayName: analog junkie
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-13T23:50:41.797Z
Comments.Text: Have you tried it without hashing it? I'm not seeing anywhere in their controller where they're checking for a hashed id, so maybe a docs error.
Comments.UserDisplayName: Brad Bell
Tags: <error-message>
Title: Contact Form Required Fields Plugin – formEntry error
ThreadText: # Contact Form Required Fields Plugin – formEntry error
  
  (Asked by: username_0 on 2018-02-09)
  
  Has anyone experience with the [ContactFormRequiredFields](https://github.com/Studiosaurus/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...")
  
  ```
  
  **Tags:** error-message
  
  > **Comments:**
  > **username_1**: I'm not familiar with a "Contact Form Required Fields" plugin and I'm not seeing it on https://straightupcraft.com/craft-plugins/. Is it something you've custom written?  
  > **username_0**: It is by username_2 who wrote a handy instruction for dynamic contact form code with the contactform plugin. http://username_2.com/blog/2016/05/13/native-email-forms-in-craft-cms.  The plugin: https://github.com/Studiosaurus/contactformrequiredfields  
  > **username_1**: Can you enable devMode and share the stack trace leading up to that error?  
  > **username_0**: Stack trace is now added.  
  > **username_1**: Guessing you're just missing this part from the [docs](https://github.com/Studiosaurus/contactformrequiredfields#using-contact-form-required-fields)?  "The entry’s id must be included in the posted variables as formId and hashed."  
  > **username_0**: @username_1: How do I hash an Id? I tried it with {{ formId|hash }} but that wasn't the solution. I am a bit clueless here, how to use the formId so the plugin can read it.  
  > **username_1**: Have you tried it without hashing it? I'm not seeing anywhere in their controller where they're checking for a hashed id, so maybe a docs error.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-02-14. Score: 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](https://solspace.com/craft/freeform) from Solspace.
  
  
  ---
  
  