Answers.Body: <p>I have finished the plugin, with much success, if you wondering you can see it here <a href="https://github.com/roundhouse/FormBuilder-Craft-CMS" rel="nofollow">https://github.com/roundhouse/FormBuilder-Craft-CMS</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-04T04:33:26.083Z
Answers.LastActivityDate: 2014-12-04T04:33:26.083Z
Answers.UserDisplayName: Vadim Goncharov
Body: <p>So I've been breaking my head trying to figure this out. I'm working on a contact form plugin. Basically I'm coping exact same code craft uses to create form "fields". I have validation working like it should. And I have 2 required fields that should return error messages. But when I try to:</p>
  
  <pre><code>craft()-&gt;urlManager-&gt;setRouteVariables(array(
    'field' =&gt; $field
  ));
  </code></pre>
  
  <p>And in the template file {{ field }}, I get.. <code>Variable "field" does not exist</code></p>
  
  <p>I can't seem to get the value to populate on the form nor display the errors because of this. Anyone had problems like this before? </p>
  
  <p>Here's my files:
  <a href="https://gist.github.com/owldesign/e01b49fdb1da3ef23ef2" rel="nofollow">https://gist.github.com/owldesign/e01b49fdb1da3ef23ef2</a></p>
  
  <p>Sorry for weird file delivery.. this comment won't let me post more than 2 links.</p>
  
  <p>Please let me know if you guys need more from me?
  Thanks.</p>
  
  <p>Edit: Repo <a href="https://github.com/owldesign/FormBuilder" rel="nofollow">https://github.com/owldesign/FormBuilder</a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T04:54:58.907Z
Comments.Text: can you just push up a repo fo the plugin to github?
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T05:49:56.023Z
Comments.Text: here's a repo to the plugin https://github.com/owldesign/FormBuilder
Comments.UserDisplayName: Vadim Goncharov
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T06:20:00.637Z
Comments.Text: does the error happen when first opening the field _edit screen, or only after making a new field with errors.
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T06:59:39.930Z
Comments.Text: Error happens when I'm making the new field. I can't get the error messages from form validation to come through to the template. The flash message comes through but the variable "field" isn't coming through to the _edit.html template from the actionSaveField in the controller.
  
  basically I'm trying to pass variable "field" to the _edit.html template from the controller using the setRouteVariables(), but it doesn't seem to work :(
Comments.UserDisplayName: Vadim Goncharov
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T09:09:14.557Z
Comments.Text: Have you tried moving the part where you return `craft()->urlManager->setRouteVariables();` into the else statement along with the `craft()->userSession->setError(Craft::t('Field Not Saved.'));` part and then remove the `return` bit? This is how I have done this in the past and things return fine.
Comments.UserDisplayName: Alec Ritson
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T17:57:30.683Z
Comments.Text: I have, I've done so much ah but nothing. Since validation works I'm going to have to figure out another way to display errors.
Comments.UserDisplayName: Vadim Goncharov
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T18:23:57.160Z
Comments.Text: Are you sure the controller action getting called on the same request as the template that’s trying to output `{{ field }}` ? No redirect happening in between, etc.?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-06T18:40:52.670Z
Comments.Text: From what I can tell yeah, because I am still getting the flash message from the controller to the template.
Comments.UserDisplayName: Vadim Goncharov
Tags: <plugin-development><validation>
Title: setRouteVariables doesn't return errors to the template
ThreadText: # setRouteVariables doesn't return errors to the template
  
  (Asked by: username_0 on 2014-11-06)
  
  So I've been breaking my head trying to figure this out. I'm working on a contact form plugin. Basically I'm coping exact same code craft uses to create form "fields". I have validation working like it should. And I have 2 required fields that should return error messages. But when I try to:
  
  ```
  craft()->urlManager->setRouteVariables(array(
    'field' => $field
  ));
  
  ```
  
  And in the template file {{ field }}, I get.. `Variable "field" does not exist`
  
  I can't seem to get the value to populate on the form nor display the errors because of this. Anyone had problems like this before?
  
  Here's my files:
  <https://gist.github.com/owldesign/e01b49fdb1da3ef23ef2>
  
  Sorry for weird file delivery.. this comment won't let me post more than 2 links.
  
  Please let me know if you guys need more from me?
  Thanks.
  
  Edit: Repo <https://github.com/owldesign/FormBuilder>
  
  **Tags:** plugin-development, validation
  
  > **Comments:**
  > **username_1**: can you just push up a repo fo the plugin to github?  
  > **username_0**: here's a repo to the plugin https://github.com/owldesign/FormBuilder  
  > **username_1**: does the error happen when first opening the field _edit screen, or only after making a new field with errors.  
  > **username_0**: Error happens when I'm making the new field. I can't get the error messages from form validation to come through to the template. The flash message comes through but the variable "field" isn't coming through to the _edit.html template from the actionSaveField in the controller.  basically I'm trying to pass variable "field" to the _edit.html template from the controller using the setRouteVariables(), but it doesn't seem to work :(  
  > **username_2**: Have you tried moving the part where you return `craft()->urlManager->setRouteVariables();` into the else statement along with the `craft()->userSession->setError(Craft::t('Field Not Saved.'));` part and then remove the `return` bit? This is how I have done this in the past and things return fine.  
  > **username_0**: I have, I've done so much ah but nothing. Since validation works I'm going to have to figure out another way to display errors.  
  > **username_3**: Are you sure the controller action getting called on the same request as the template that’s trying to output `{{ field }}` ? No redirect happening in between, etc.?  
  > **username_0**: From what I can tell yeah, because I am still getting the flash message from the controller to the template.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2014-12-04. Score: 1
  
  I have finished the plugin, with much success, if you wondering you can see it here <https://github.com/roundhouse/FormBuilder-Craft-CMS>
  
  
  ---
  
  