How to redisplay form contents

Im creating my own form validators, and im submitting the form to
itself. My validators work, but the hell, when the form gets reloaded
all the contents are lost and if that would happen in real im not sure
he/she would bother retyping all the stuff in. How do I get the form
data loaded again (without using params or session)

Petr

On Oct 5, 1:23 pm, Petr [email protected] wrote:

Im creating my own form validators, and im submitting the form to
itself. My validators work, but the hell, when the form gets reloaded
all the contents are lost and if that would happen in real im not sure
he/she would bother retyping all the stuff in. How do I get the form
data loaded again (without using params or session)

It sounds like you’re using the form_tag helpers (e.g. text_field_tag)
rather than the form helpers (e.g. text_field). The form helpers hook
into ActiveRecord objects and help you do this kind of redisplay
easily, but with the form_tag helpers you need to specify the values
manually.

For instance, if I have a text field like this:

text_field_tag(“name”)

then it will always render as empty when you reload the page, because
I’m not telling it what value to display.

However, if my controller picks up the data like this:

@name = params[:name]

then I can change the text field tag to this:

text_field_tag(“name”, @name)

and it will use the contents of @name as the default value of the text
field when the page is loaded.

Chris

Is it possible to redirect form contents? ie. user submits a form to
itself, then it redirects to a different action and display the contents
of the form there, without using sessions?

Petr

Chris M. wrote:

On Oct 5, 1:23 pm, Petr [email protected] wrote:

Im creating my own form validators, and im submitting the form to
itself. My validators work, but the hell, when the form gets reloaded
all the contents are lost and if that would happen in real im not sure
he/she would bother retyping all the stuff in. How do I get the form
data loaded again (without using params or session)

It sounds like you’re using the form_tag helpers (e.g. text_field_tag)
rather than the form helpers (e.g. text_field). The form helpers hook
into ActiveRecord objects and help you do this kind of redisplay
easily, but with the form_tag helpers you need to specify the values
manually.

For instance, if I have a text field like this:

text_field_tag(“name”)

then it will always render as empty when you reload the page, because
I’m not telling it what value to display.

However, if my controller picks up the data like this:

@name = params[:name]

then I can change the text field tag to this:

text_field_tag(“name”, @name)

and it will use the contents of @name as the default value of the text
field when the page is loaded.

Chris