Solved

an urgent question, thanks!

Posted on 2003-11-10
9
327 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use System DSN 6 89
Has my website been infiltrated? 21 69
Systems talking to each other 5 142
http to https 3 70
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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