Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Oh wise and patient brethren,

I haven't had to do any HTML/CGI development in many a moon (oh, 10 years or so). I have a new project which gave me an opportunity to try some new things, so I'm playing with Catalyst and Template Toolkit. Very cool stuff I must say.

Let's assume for the sake of argument that there's a form where users can enter lists of books and authors. There's no limit to the number they can enter, and there's no way for me to know how many they will want to enter. So what I want it a way to dynamically add more fields with a button(?)

My head was firmly mired in Catalyst/TT, so my first effort was:

sub form_create :Local { my ( $self, $c ) = @_; $c->stash->{entry_fields} = 2; $c->stash->{template} = 'requests/new_request.tt2'; }
Where in new_request.tt2 I have:
[% printField = 1; WHILE printField <= entry_fields %] <tr> <td>Book:</td> <td><input type="text" name="book"</td> <td>By:</td> <td><input type="text"name="author"></td> </tr> [% printField = printField + 1; END; %]
That worked fine, and allowed me to control the number of fields in my form_create() routine. What I wanted to do then was add a way to the form to increment the entry_fields and regenerate the form. When I got to that point, I realized I didn't have a clue what to do

Some folks on #catalyst suggested I should use javascript, but I know absolutely nothing about JS, and can't fathomn where to start (and the caution "Prepare for Hell" someone offered me didn't help)

So maybe I'm thinking orthogonal to the problem, but I'm not sure how to proceed...any pushes in the right direction are appreciated.

Thanks,
Jeff

PS: Yes, I'm aware the answer here may have nothing to do with perl, Catalyst, or TT, so try and be gentle please.


In reply to Adding fields to a form using Catalyst/TT by HuckinFappy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2023-01-29 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?