Need help with how to do a specific part of my form...

I am creating a form in Dreamweaver that I will use to add records to my recipes database. My recipes database has multiple tables, and many one-to-many relationships between tblRecipes and other tables.
I need help with how I set up the form to put in the recipe directions.
I will have one or more "steps", with each step having a number and some text associated with it.
For this, I have a table named tblRecipeSteps that contains the following fields:
StepID (key); RecipeID (relates to tblRecipes); StepNum; StepDetail
So I need a way to input multiple steps on my Recipe form.
I'm experienced with creating repeating regions in Dreamweaver for displaying EXISTING data ... I guess I'm looking for the reverse of this ... how to have repeating regions for input?
Thanks.
alicia1234Asked:
Who is Participating?
 
Jason C. LevineNo oneCommented:
Hi alicia,

You can do this one of two ways...

1) If you know (or ask for) the number of regions you will need to enter, you can make a table-based form that has that number of "regions" with the same fields in each region.  The field names would need to be array elements (i.e., input name=text[0] , input name=text[1], etc) and when submitted, the form reads all fields into an array.  You then process the array one group at a time and write each group into the table as a new row.  This is not supported by Dreamweaver, so you will get involved in hand-coding.

2) The easier way is to add the new record to tblRecipes and pull out the primary key value on the next page (form for recipe steps).  Have that form insert the step and loop back to itself for the next one, keeping the tblRecipes primary key as a hidden value the whole time.  Have two submit buttons for the form, one which adds the step and then loops back to the blank form, the other adds the step and goes back to the main page.  This involves checking to see which submit button was hit and also involves a little hand-coding, but not nearly as much as dealing with the array would...
0
 
alicia1234Author Commented:
OK ... so there is no "magic way" to do it. It involves basically letting the user enter a step and then click a button for "next step" ... until they are done? With each "next step", I would add another field to the form?
0
 
alicia1234Author Commented:
But when I then process the form ... is there a way to "array" it ... so I know how many steps there were?
And then have code to process an array of steps?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Jason C. LevineNo oneCommented:
>> It involves basically letting the user enter a step and then click a button for "next step" ... until they are done?

That would be the easiest way considering what you have told me about the set up.  Otherwise you have to ask the user "How many fields will you need?" and return that number of blank fields for steps or just provide some maximum number of blank fields and write a routine that discards the nulls on submit and processes the rest using the array method.  You're better off letting them keep submitting until they select "Submit and Finish" or whatever the second submit button will be called.

>> But when I then process the form ... is there a way to "array" it ... so I know how many steps there were?

If you have the tables set up as a one-to-many, you automatically know this just by selecting from both tables joining on tblRecipes primary key.  The join will return the number of records the user entered.
0
 
alicia1234Author Commented:
OK .. I'll try it and get back to you.
Thanks.
0
 
alicia1234Author Commented:
>> 2) The easier way is to add the new record to tblRecipes and pull out the primary key value on the next page (form for recipe steps).  

My primary key for tblRecipes is an autonumber field named RecipeID ... how do I "pull out the primary key value on the next page" (my steps page?)
0
 
Jason C. LevineNo oneCommented:
What server tech are you using?
0
 
alicia1234Author Commented:
Coldfusion
0
 
Jason C. LevineNo oneCommented:
That is addressed here:

http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21469141.html

Insert the record, then use @@IDENTITY to pull the pk into a value and send it to the next page or use the sort by PK descending and pull the first record trick that is the accepted answer.  @@IDENTITY is a better way to go.
0
 
alicia1234Author Commented:
Thanks so much. I think I've "got it" now!
In the "Accepted Answer", number 2 is the way I am going to proceed.
Thanks again ... you've helped me before and I really appreciate it. When I publish my website I will let you know. (But I'm sure you'll hear from me again before then!) ;-)
0
 
Jason C. LevineNo oneCommented:
Great!

I cook, so I'll be really interested to see your site live...
0
 
alicia1234Author Commented:
I will be using MySQL ... I read in the referenced post that @@IDENTITY could be used for SQL Server ... will it also work for MySQL? (Can't find it in my MySQL book!)
0
 
Jason C. LevineNo oneCommented:
Should work...

CF is not my preferred environment, so I don't have a definite answer for you.  The CF TA here will...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.