Solved

an urgent question, thanks!

Posted on 2003-11-10
9
323 Views
Last Modified: 2013-12-24
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!
0
Comment
Question by:xiaobing
9 Comments
 
LVL 1

Accepted Solution

by:
kjuliff earned 125 total points
Comment Utility
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
0
 
LVL 25

Assisted Solution

by:James Rodgers
James Rodgers earned 125 total points
Comment Utility
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

0
 
LVL 17

Expert Comment

by:anandkp
Comment Utility
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
0
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 
LVL 4

Expert Comment

by:procept
Comment Utility
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

0
 
LVL 17

Expert Comment

by:anandkp
Comment Utility
confusing ??? why do u think so ???

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

Expert Comment

by:iamari
Comment Utility
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
0
 
LVL 4

Expert Comment

by:procept
Comment Utility
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

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now