Solved

an urgent question, thanks!

Posted on 2003-11-10
9
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 1

Accepted Solution

by:
kjuliff earned 125 total points
ID: 9715851
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
ID: 9715875
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
ID: 9720022
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 4

Expert Comment

by:procept
ID: 9720699
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
ID: 9720807
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
ID: 9722370
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
ID: 9753564
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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