P is for Practical | |
PerlMonks |
dynamically adding formsby MCS (Monk) |
on Mar 02, 2004 at 17:32 UTC ( [id://333310]=perlquestion: print w/replies, xml ) | Need Help?? |
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. I call each field qtyn, ammountn, descriptionn where n is the ingID. (Used to tell which one's which) 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?
Back to
Seekers of Perl Wisdom
|
|