Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [newbie] Auto-populating template forms?

Reply
Thread Tools

[newbie] Auto-populating template forms?

 
 
Mark Probert
Guest
Posts: n/a
 
      08-04-2004

Hi, all.

I have just started playing with Cerise and web apps, and I have run
across a bit of a problem. How do I populate a form, with array values
programatically?

For example, how could I get a form with the letters A-M (as an array)
displayed as radio buttons?


-mark.
 
Reply With Quote
 
 
 
 
Mark Hubbart
Guest
Posts: n/a
 
      08-06-2004

On Aug 4, 2004, at 4:11 PM, Mark Probert wrote:

>
> Hi, all.
>
> I have just started playing with Cerise and web apps, and I have run
> across a bit of a problem. How do I populate a form, with array
> values programatically?
>
> For example, how could I get a form with the letters A-M (as an array)
> displayed as radio buttons?


I assume you are using the cgi module? You probably want something like
this:

#....

cgi.form("myForm") do
values = ("A".."M")
values.map do |value|
cgi.radio_button(value) + cgi.strong{value} + cgi.br
end.join
end

#....


this gives:

<FORM METHOD="myForm" ENCTYPE="application/x-www-form-urlencoded">
<INPUT NAME="A" TYPE="radio">
<STRONG>
A
</STRONG>
<BR>
<INPUT NAME="B" TYPE="radio">
<STRONG>
B
</STRONG>
<BR>
[snip]
<INPUT NAME="L" TYPE="radio">
<STRONG>
L
</STRONG>
<BR>
<INPUT NAME="M" TYPE="radio">
<STRONG>
M
</STRONG>
<BR>
</FORM>


you have to map and join to produce the string, which gets passed to
the enclosing functions.

HTH,
Mark



 
Reply With Quote
 
 
 
 
Mark Probert
Guest
Posts: n/a
 
      08-06-2004
Mark Hubbart wrote:

>
>>
>> For example, how could I get a form with the letters A-M (as an array)
>> displayed as radio buttons?

>
>
> I assume you are using the cgi module? You probably want something like
> this:
>

Thanks, Mark.

I am using Cerise, which has a Amrita-like templating system, rather
than CGI.

I have a template that contains the following (moved from radio buttons
to a drop-down box):

<form method="post" action="form.ahtml">
<div class="fields">
<div>
<label> Select Node: </label>
<select name="option">
<option id="node" value="node" selected="@__node">node

</option>
</select>
</div>
<div class="submit">
<input type="submit" name="submit" value="Select"/>
</div>
</div>
</form>

And code that looks like:

class Form < Cerise::FormHandler
attr_accessor ption

def load(request, response)
{:node => ["a", "b", "c"] }
end
end

I am not sure how to get the values back from the form. Is it in
@__node? How do I set that programmatically?

I guess this maybe one for the guy who wrote Cerise ...

-mark.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
r H2 deduce deduce template argument of a template class inheritingfrom a non template base? nguillot C++ 5 03-08-2009 05:56 PM
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments