Pass value from a form to CGI scropt : CGI Form « CGI « Ruby

Pass value from a form to CGI scropt


require 'cgi'
cgi =

from = cgi['from'].to_i
to = cgi['to'].to_i

number = rand(to-from+1) + from

puts cgi.header

puts "<html><body>#{number}</body></html>"

An associated, but basic, form that could send the correct data would have HTML:

<form method="POST" action="">
   For a number between 
   <input type="text" name="from" value="" /> and
   <input type="text" name="to" value="" /> 
   <input type="submit" value="Click here!" />


Related examples in the same category

1.Create a Page in HTML for Accepting the Customer Information
2.Get value from a form
3.Is name set in cgi
4.Post a message