[newbie] Auto-populating template forms?

Discussion in 'Ruby' started by Mark Probert, Aug 5, 2004.

  1. Mark Probert

    Mark Probert Guest

    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.
     
    Mark Probert, Aug 5, 2004
    #1
    1. Advertising

  2. Mark Probert

    Mark Hubbart Guest

    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
     
    Mark Hubbart, Aug 6, 2004
    #2
    1. Advertising

  3. Mark Probert

    Mark Probert Guest

    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 :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.
     
    Mark Probert, Aug 6, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Galvin

    Disabling auto-populating of form elements

    Jason Galvin, Dec 10, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    366
    Teemu Keiski
    Dec 10, 2003
  2. Chris Theis
    Replies:
    2
    Views:
    487
    Chris Theis
    Jul 24, 2003
  3. tom_usenet
    Replies:
    0
    Views:
    552
    tom_usenet
    Jul 24, 2003
  4. linkswanted
    Replies:
    1
    Views:
    949
  5. Replies:
    0
    Views:
    143
Loading...

Share This Page