3

I have an application which requires visitors to fill out a form and then it redirects to a second page. The client does not want to require visitors sign up to view this page, only to fill out the form.

The way I am attempting to do this is by creating a session variable when the page is visited and then checking to see if the variable exists before the next page is accessible. Is it possible to delay the creation of the session variable until the submit action is processed? If so what would that look like?

Also, can anyone think of a better way to do this? Sorry, this is probably a dumb question.

2
  • How do you want to handle returning user who he visited your website 1hour/1day/1year ago? Commented Nov 3, 2015 at 1:45
  • Preferably I would like them to fill out the form if its been more than an hour or two. Commented Nov 3, 2015 at 2:07

1 Answer 1

2

The session cookie would be declared after the first submit.

I presume the first submit will load up a controller#action in which you'll then redirect to the next page. Just set the session in there:

#app/views/forms/1.html.erb
<%= form_tag form_1_submit_path do %>
  ...
<% end %>

This will allow you to do the following:

#app/controllers/forms_controller.rb
class FormsController < ApplicationController
   def form_1_submit
      session[:value] = params[:value]
      redirect_to form_2
   end
end

Thus you'll have session[:value] all set and ready to use on the next form:

#app/views/forms/2.html.erb
<%= form_tag .... do %>
   <%= text_field_tag :test, value: session[:value] %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.