Forms

H

Harry Sa

Hi. I'm new here, and new at programming Ruby. I have a question about
it though.

Is there a possible way to write forms in HTML, and then read them using
a Ruby equivalent to the PHP $_GET or $_POST on the page where the
method points?
 
D

David Moreno

[Note: parts of this message were removed to make it a legal post.]

Yes, there is.

On your ruby application endpoint, you would need something like this:

require "cgi"
cgi = CGI.new
value = cgi['field_name'] # <== value string for 'field_name'

And do all sorts of Ruby operations:

# if not 'field_name' included, then return "".
fields = cgi.keys # <== array of field names

# returns true if form has 'field_name'
cgi.has_key?('field_name')
cgi.has_key?('field_name')
cgi.include?('field_name')

On the same scoop of concept you were viewing it, cgi['field_name'] it's
kind of the same as PHP's $_REQUEST['field_name'].

Actually, I extracted that sample above from the cgi module documentation
somebody else already pointed to you.

Enjoy,
D.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,283
Messages
2,571,405
Members
48,098
Latest member
inno vation

Latest Threads

Top