an urgent question, thanks!

Hi, everybody:

Now, I am working on a survey using ColdFusion. It's my first time to use ColdFusion to design a real project. I have a question here: the survey is very long and it has about 40 questions. According to the requirement, I have to separete the survey to 4 different pages. That is, on each page, i will use a form. So, if I want to add the input result, how can I design the insert page? I should design a insert page for each of them? Another question is: on the 4 pages, inside the form, how to define the action="?", the action page for these 4 pages are the same?

Thanks a lot!
xiaobingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kjuliffCommented:
You can't have the action the same for the four pages. I'd only code the form proper on the final page. I would have 3 temporary forms for the other pages each going to the next temp form page.

eg
page 1 form1 action  = form2 submit name = "next" pass input filds to form2
page 2 form2 action = form3 submit name = "next" value of form1 fields passed to next page as hidden
page 3 form3 action = final form submit  name = "next"  value of form1 and form2 fields passed to next page as hidden
page 4 final form - actually does the work as has its own input fields and the passed hidden ones from the previous forms

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James RodgersWeb Applications DeveloperCommented:
try something like this

survey section1

<form name="survey1" action="survey2.cfm" method="post">


and in survey2.cfm

<cfquery name="" datasource=""
insert into tblsurvey q1,q2,q3,q4,q5 values(<cfqueryparam value="form.q1">,...)

</cfquery>

and then in the same page
<form name="survey2 action="survey3.cfm">

etc

anandkpCommented:
Hi

ur requirement is a special case i wld say :)

what i wld do is - have the same page [instead of 4 pages] do the job for me

<form name="frm" action="onesinglepage.cfm" method="post">
<cfif condition 1>
   show the first form fields
<cfelseif >
show 2nd form details
..


..

</cfif>
<input type="submit">
</form>

On "onesinglepage.cfm" identify which form is being submitted - by using a ID & do the needfull processing with the DB & after that redirect teh user back to the first page with next ID - so as to show the next form ...

HTH .... let me know incase u need more explanation !

K'Rgds
Anand
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

proceptCommented:
Hi,

you can make page 2 the action for page 1, make page 3 the action of page 2, etc.

On each page you can store the previous entered values as hidden fields or as session variables. After the last page, do just one insert. Anand is right, it can be done on a single page, but, that makes the code much longer and maybe a little confusing. ;-)

HTH,

Chris

anandkpCommented:
confusing ??? why do u think so ???

I guess a carefully planned code - is much shorter, efficient, easy to understand, implement & maintain !
iamariCommented:
only problem with the solution above is the *abandoned cart* syndrom. what if user never finishes the whole thing? you don't want to save incomplete results.

passing along field values from one page to another is cumbersome, especially when you want to make changes.

i would create a scrap table, identical to the real one. create a single action template and save bunches of fields to the scrap table until the end. if everything checks out, copy the whole record from the scrap table to the new one

<cftransaction>

<!--- comes from first page, no ID yet --->
<cfif not isDefined('form.myID')>
    <cfquery name="getID" datasource="myDNS">
       if (select max(myID) from myScrapTable) is null
       select myID=1
       else select max(myID)+1 as myID from myScrapTable
   </cfquery>

   <cfquery name="saveBunch" datasource="myDNS">
       insert into myScrapTable (myID, userField1, userField2)
       values (#getID.myID#, '#userField1#', '#userField2#')
   </cfquery>

<!--- comes for a later page, ID should exist --->
<cfelse>
   <cfquery name="saveBunch" datasource="myDNS">
       update myScrapTable set
       userField3 = '#form.userField3#'
       userField4 = '#form.userField4#'
       where myID = #form.myID#
   </cfquery>
</cfif>

</cftransaction>

pass the unique ID back to next user page, like:

<cflocation url="myNextPage?myID=#myID#">

all following pages should include a hidden field for myID
<cfoutput>
<input type="hidden" name="myID" value="#myID#">
</cfoutput>

on the last page, pass a variable, say like: <input type="hidden" name="finish">

on the action page, add another transaction, like:

<!--- last bunch came from last user page, save everything on production table --->
<cfif isDefined('form.finish')>
  <cftransaction>
   <!--- get the whole record from scrap table --->
      <cfquery name = "getScrapRecord" datasource="myDNS">
         select * from myScrapTable where myID=#form.myID#
      </cfquery>
   <!--- get a prodID --->
   <cfquery name="getProdID" datasource="myDNS">
       if (select max(myProdID) from myProdTable) is null
       select myProdID=1
       else select max(myProdID)+1 as myProdID from myProdTable
   </cfquery>
   <cfquery name="mainQry" datasource="myDNS">
       insert into myProdTable (myProdID, userField1, userField2, userField3, userField4)
       values = (#myProdID#, getScrapRecord.userField1, getScrapRecord.userField2,
       getScrapRecord.userField3, getScrapRecord.userField4)
   </cfquery>
  </cftransaction>
</cfif>

after that, eventually run a scheduled template to clean up the scrap table periodically of incomplete records
proceptCommented:
Hi,

@Anand:

> confusing ??? why do u think so ???

> I guess a carefully planned code - is much shorter, efficient, easy to understand, implement & maintain !

I agree 100%!!!

But... ;-))

Doing all form parts and actions in one single page will make the code per page always longer and less easy to read. For an experienced CF programmer that should not be a problem, but, especially beginners tend to be confused (and frustrated) by long code.


@iamari

> only problem with the solution above is the *abandoned cart* syndrom.
> what if user never finishes the whole thing? you don't want to save incomplete results.

Well, you don't save incomplete results when you pass along field values from one page to another or use cookie.

> passing along field values from one page to another is cumbersome, especially when you want to make changes.

Depends on how you set up your form and how you pass the values. Can be done in a single loop for all fields (like 3 lines of code or so).

A scrap table also is a good solution, but, requires more queries plus a cleanup...

There's always more than one possible solution, in the end it depends on your taste. ;-)

Cheers,

Chris

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.