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






Pass value from a form to CGI scropt


#!/usr/bin/ruby

require 'cgi'
cgi = CGI.new

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="http://www.example.com/test.cgi">
   For a number between 
   <input type="text" name="from" value="" /> and
   <input type="text" name="to" value="" /> 
   <input type="submit" value="Click here!" />
</form>

 








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