Form Data
File: hello_controller.rb
class HelloController < ApplicationController
def showform
end
def show_formdata
@name = params[:name]
@prog_languages = params[:prog_languages] || []
@operating_systems = params[:operating_systems] || []
end
end
File: show_formdata.rhtml
<h2>Display Posted Form Data</h2>
Name: <%= @name %> <br />
Programming Languages: <%= @prog_languages.join(", ") %> <br />
Operating Systems: <%= @operating_systems.join(", ") %> <br />
<p>
YAML Output from Debug: <br />
<%= debug(params) %>
</p>
File: showform.rhtml
<h2>A Simple Form</h2>
<%= form_tag(:action => "show_formdata") %>
<p>Text Field:
<%= text_field_tag("name","Aneesha") %></p>
<p>Drop-down Selection Box:
<% languages = ["Ruby", "Java", "C#"].map do |lang|
"<option>#{lang}</option>"
end.to_s %>
<%= select_tag("prog_languages[]", languages, :multiple => "true") %></p>
<p>Checkboxes:
<%= check_box_tag("operating_systems[]","Windows") %> Windows
<%= check_box_tag("operating_systems[]","Linux") %> Linux
<%= check_box_tag("operating_systems[]","Mac") %> Mac
</p>
<%= submit_tag("Submit Form") %>
<%= form_tag %>
getSetFormDataWithFormTag.zip( 91 k)Related examples in the same category