# Repopulating form after validation error

**URL:** <https://discuss.rubyonrails.org/t/repopulating-form-after-validation-error/16154>\
**Category:** rubyonrails-talk\
**Created:** [July 25, 2007, 2:32pm UTC](https://discuss.rubyonrails.org/t/repopulating-form-after-validation-error/16154 "2007-07-25T14:32:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff\_emminger](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jeff\_emminger](https://discuss.rubyonrails.org/u/jeff_emminger)\
**Post date:** [July 25, 2007, 2:32pm UTC](https://discuss.rubyonrails.org/t/repopulating-form-after-validation-error/16154/1 "2007-07-25T14:32:05Z")

</div>

that should work just fine provided you don't do a redirect in your controller upon failure... you need something like

MyController

&nbsp;&nbsp;def send\_mail

&nbsp;&nbsp;&nbsp;&nbsp;if request.post? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if everything validates etc &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = 'Message sent' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to :action =\> :message\_sent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :action =\> :contact\_form &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;end

end

note that if there was an error you render an action, not redirect to it. if you redirect you are responsible for preserving all params yourself.
