[newbie] Auto-populating template forms?

M

Mark Probert

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.
 
M

Mark Hubbart

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
 
M

Mark Probert

Mark said:
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 :eek: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.
 

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
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top