# Forms

**URL:** <https://www.ruby-forum.com/t/forms/128811>\
**Category:** Ruby\
**Created:** [February 11, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/forms/128811 "2008-02-11T19:17:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harryspier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@harryspier](https://www.ruby-forum.com/u/harryspier)\
**Post date:** [February 11, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/forms/128811/1 "2008-02-11T19:17:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![harryspier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@harryspier](https://www.ruby-forum.com/u/harryspier)\
**Post date:** [February 11, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/forms/128811/2 "2008-02-11T19:42:35Z")

</div>

Harry Sa wrote:

> 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?

Check out Ruby’s CGI library at  
[http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html).

HTH,  
Jim

---

<div class="post-metadata">

**Author:** ![harryspier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@harryspier](https://www.ruby-forum.com/u/harryspier)\
**Post date:** [February 11, 2008, 11:21pm UTC](https://www.ruby-forum.com/t/forms/128811/3 "2008-02-11T23:21:28Z")

</div>

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.
