MCS has asked for the wisdom of the Perl Monks concerning the following question:
I'm creating a little web based recipe database program and I have the majority of it done and working. I initially created a script to parse existing txt files (and thanks to antiword, word files) and insert them into the database. I then added a editform.pl cgi script to edit the values in case something went wrong. Now I want to add the ability to enter in a new recipe via a web form. Now I could have two text boxes and then parse the ingredients but that can be prone to errors when things don't follow the standard qty, amt, description (like 1 cup sugar). Therefore I want to do fields for the qty (1) amt (cup) and description (sugar). However there is no telling how many ingredients there are.
I thought the best way to handle this would be to have a few fields up and if they are blank, just not use them. However, if the user has a long list of ingredients, I would like the ability to add a set of three text fields. What would be the best way to go about this?
My edit recipe forms look like this:
Just some references: the $ingredientAoH is an array of hashes where qty, amt and des are the three keys and each element of the array indicates a seperate ingredient. Then there is also the ingID key which is a unique ingredient key from the database... it is naturally hidden from the user and is just used for updating the database.print "Qty:", $query->textfield(-name=>"qty$ingredientAoH[$i]{ingID}", -default=>"$ingredientAoH[$i]{ +qty}", -size=>'10', -maxlength=>'20', "\n"); print "Amt:", $query->textfield(-name=> "ammount$ingredientAoH +[$i]{ingID}", -default=> "$ingredientAoH[$i] +{amt}", -size=>10, -maxlength=>100, "\n"); print "Des:", $query->textfield(-name=> "description$ingredien +tAoH[$i]{ingID}", -default=> "$ingredientAoH[$i] +{des}", -size=>50, -maxlength=>100), "\n"; print $query->hidden(-name=>"ingID$ingredientAoH[$i]{ingID}", +-default=>"$ingredientAoH[$i]{ingID}"), "<br>\n";
Should I just have a parameter indicating the number of fields and then just increment that on a add ingredient button and reload the form? If so how do I keep already existing values from disapearing? Should I pass my ingredientsAoH as a parameter?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dynamically adding forms
by BUU (Prior) on Mar 02, 2004 at 21:13 UTC |