Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF Insert in a form that spans multiple pages 3

Status
Not open for further replies.

Buffalo

Programmer
Jan 9, 2000
1
US
I have the need to create a data entry form that <br>
spans multiple pages (it's a long form - so I want to<br>
divide it 3 sepearate pages). How do you use CFINSERT to insert the data? NOTE: all data goes to ONE table (MS ACCESS)
 
You could &quot;forward&quot; the data from each page of the form using hidden form fields, then all the data will be together for the last cfinsert....<br>
<br>
example:<br>
<br>
PAGE 1<br>
&lt;input type=&quot;text&quot; name=&quot;clientname&quot;&gt;<br>
<br>
PAGE 2<br>
&lt;input type=&quot;hidden&quot; name=&quot;clientname&quot; value=&quot;#form.clientname#&quot;&gt;<br>
&lt;input type=&quot;text&quot; name=&quot;clientaddress&quot;&gt;<br>
<br>
PAGE 3<br>
&lt;input type=&quot;hidden&quot; name=&quot;clientname&quot; value=&quot;#form.clientname#&quot;&gt;<br>
&lt;input type=&quot;hidden&quot; name=&quot;clientaddress&quot; value=&quot;#form.clientaddress#&quot;&gt;<br>
&lt;input type=&quot;text&quot; name=&quot;clientemail&quot;&gt; <p>Doug Trocino<br><a href=mailto:dtrocino@tecumsehgroup.com>dtrocino@tecumsehgroup.com</a><br><a href= Forums</a><br>Web Application Developer<br>
Tecumseh Group, Inc.<br>
Sponsors of Tek-Tips Forums<br>
 
The Idea of using hidden form fields can be made a lot easier by using a custom tag.. I took the initial idea from Ben Forta and made it a lot easier to understand.<br>
<br>
Create a page called embedfields.cfm in your c:\cfusion\custom tags directory. The page should consist of the code below:<br>
<br>
&lt;cfsetting enablecfoutputonly=&quot;Yes&quot;&gt;<br>
&lt;CFIF IsDefined(&quot;FORM.fieldnames&quot;)&gt;<br>
&lt;cfloop index=&quot;Var&quot; list=&quot;#fieldnames#&quot;&gt;<br>
&lt;cfoutput&gt;<br>
&lt;input type=&quot;Hidden&quot; name=&quot;#var#&quot; value=&quot;#evaluate('form.' & var)#&quot;&gt;<br>
&lt;/cfoutput&gt;<br>
&lt;/cfloop&gt;<br>
&lt;/CFIF&gt;<br>
&lt;cfsetting enablecfoutputonly=&quot;no&quot;&gt;<br>
<br>
Nothing else... no &lt;html&gt; or &lt;body&gt; tags just the code above.<br>
<br>
Next you need to run it from your code and always within form tags. eg. <br>
&lt;form method=&quot;post&quot; action=&quot;page3.cfm&gt;<br>
&lt;cf_embedfields&gt;<br>
&lt;/form&gt;<br>
<br>
What the tag does is take the form fields posted from the previous page and dumps them to Hidden<br>
Form fields. So the tag isn't needed on the first page only on the pages with forms that follow.<br>
<br>
Your &lt;cfinsert&gt; should only then need to define the table and datasource to put all the data in thats all.<br>
<br>
If you need to skip some form fields before they go into &lt;cfinsert&gt; then use the code below just before your &lt;cfinsert&gt; tag:<br>
<br>
&lt;cfset mylist=&quot;&quot;&gt;<br>
&lt;cfloop list=&quot;#fieldnames#&quot; index=&quot;var&quot;&gt;<br>
&lt;!--- define fields to skip here ---&gt;<br>
&lt;cfif (#var# is &quot;timestamp&quot;) or (#var# is &quot;recordid&quot;) or (#var# is &quot;action&quot;) or (#var# is &quot;override&quot;)&gt;<br>
&lt;cfelse&gt;<br>
&lt;!--- Include all other fields into variable mylist ---&gt;<br>
&lt;cfset mylist=#ListAppend(mylist, var)#&gt; <br>
&lt;/cfif&gt;<br>
&lt;/cfloop&gt;<br>
<br>
Your &lt;cfinsert&gt; should then be &lt;CFINSERT datasource=&quot;yourds&quot; TABLENAME=&quot;yourtable&quot; FIELDS=&quot;#mylist#&quot;&gt;<br>
<br>
Problem solved.....<br>
<br>
Arachind....
 
Awesome!!!! I <b><i>LOVE</i></b> a solution that automates the process.....:) <p>Doug Trocino<br><a href=mailto:dtrocino@tecumsehgroup.com>dtrocino@tecumsehgroup.com</a><br><a href= Forums</a><br>Web Application Developer<br>
Tecumseh Group, Inc.<br>
Sponsors of Tek-Tips Forums<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top