If I understand your question correctly, it's pretty easy to do what you
need.

When someone comes to that form intending to update a record, you'll need to
have some way to identify which record is desired.  So, on a previous page,
you might list records in the following way:

<cfoutput query="GetProposals">
        <a href="proposal_form.cfm?proposal_id=#proposal_id#">#CustFirstName#
#CustLastName# #CustCity#</a><br>
</cfoutput>

When the user reaches the second page you'll have url.proposal_id with a
value of, lets say, "27". So in your proposal_form.cfm page you'll do
something like:

Note: The database update or insert code goes here - look below - I added it
there so you could see this stuff first

<cfif IsDefined('url.proposal_id'>
        <!--- if we have a proposal_id, use it --->
        <cfquery name="GetProposal" datasource="proposals">
                SELECT CustFirstName, CustLastName, Cust....
                FROM PROPOSAL_TABLE
                WHERE PROPOSAL_ID = #url.Proposal_ID#
        </cfquery>

        <cfscript>
                strCustFirstName = GetProposal.CustFirstName;
                strCustLastName = GetProposal.CustLastName;
                strCustCity = GetProposal.CustCity;
                intCustIsCurrent = GetProposal.CustIsCurrent;
                ...
        </cfscript>

<cfelse>
        <!--- if we don't have a proposal_ID, create default variables to populate
the form --->
        <cfscript>
        strCustFirstName="";
        strCustLastName="";
        strCustCity="";
        intCustIsCurrent = 0;
        ...
        </cfscript>
</cfif>

Now that your variables are populated, regardless of whether you had a
record ID passed or not, you can display your form (as you have in the
example data you sent.  However, notice the variable names I used above.  In
the form fields, you will want to use these variables:

Note: I almost always post a form to itself.  You can really control the
actions this way.

<form action="#cgi.script_name# ...>

<input type="text" name="CustFirstName" value="#strCustFirstName#"
maxlength="30" size="30">

etc...

<input type="radio" name="CustIsCurrent" value="#intCustIsCurrent#" <cfif
intCustIsCurrent EQ 1>CHECKED</cfif>>Current!
<input type="radio" name="CustIsCurrent" value="#intCustIsCurrent#" <cfif
intCustIsCurrent EQ 0>CHECKED</cfif>>Not Current!

</form>


In the TOP of your page you will check to see if the form has been
submitted. If so, you need to decide whether to do an update or an insert:

<!--- this query is used twice - once in the following section, and once
later on. The field noted will be populated if the user
has filled out a previous form --->

<cfquery name="CheckData" datasource="myDataSource">
SELECT Some_Field_That_Should_Be_Here_If_A_Record_Exists
FROM myTable
WHERE Proposal_id = #url.Proposal_ID#
</cfquery>


<cfif cgi.content_length GT 0>

        <cfif CheckData.RecordCount GT 0>
                <cfquery name="UpdateRecord" datasource="myDataSource">
                UPDATE myTable
                SET CustFirstName = #form.CustFirstName#,
                    CustLastName = #form.CustLastName#,
                    etc...
                WHERE proposal_id = #url.Proposal_ID#
                </cfquery>
        <cfelse>
                <cfquery name="InsertRecord" datasource="myDataSource">
                INSERT INTO myTable (CustFirstName, CustLastName, CustCity, ....)
                VALUES
                        
('#form.strCustFirstName#','#form.CustLastName#','#form.CustCity#', ...)
                </cfquery>
        </cfif>

        <!---Display a thank you notice or something, or possibly move to another
form --->

        <!---Thanks --->
        Thank you for doing something!<p>
        Now, do something else: <a href="somewhere.cfm">Go Somewhere</a>
        <cfabort>

        (or)

        <!--- move to another form page --->
        <cflocation url="NextForm2.cfm">
</cfif>


There's a few things that I haven't included here, things like maintaining
state between multiple forms, etc.  The nice thing about this methodology is
that the user can switch back and forth between multiple forms and never get
fouled up.  You need to remember to add url vars to any links that could
come back, etc..  I usually set either a cookie or a client variable with
the record ID to determine which record is being used, if any.

If you do have multiple forms, you also want to check and see if previous
forms have been filled out and submitted.  If so, you only need to do an
update in subsequent forms. If they haven't, send them backwards:

<!--- using the earlier query, check for an existing record. If not, send to
'previous' form --->
<cfif CheckData.RecordCount EQ 0>
        <cflocation url="myPreviousForm.cfm">
</cfif>

With this, you can let the user bounce from form to form in either
direction.  If the record does exist, you only need to code an update.

The other nice thing about this methodology is that you use the same form
for inserts and updates - no need to have seperate forms. I really hate
typing the same thing more than once, and this is a real saviour!

PS - please forgive any typos - this is off the top of my head.. I love
writing code after partying!

Good Luck!

Jeff


-----Original Message-----
From: Hubert Earl [mailto:[EMAIL PROTECTED]]
Sent: Sunday, May 13, 2001 12:48 AM
To: CF-Talk
Subject: How to make sure that 'select', 'textarea' and 'checkbox' data
fields are filled from the database when performing an update?


hi,

  i'm working on a form which will either  add to or  update the columns of
an Access database.  in order that the fields be filled with data already
submitted if an update is to be done, i'm using the 'value' attribute  for
text input fields.  however, i also have as input fields the 'select',
'textarea' and 'checkbox' data fields.  how do i ensure that those fields
are filled with data from the database, in the case of an update situation?
the update will be performed when the form is passed to an action file which
will use sql to perform the update.

Below is the code i'm dealing with:

<CFOUTPUT>

<HTML>
<HEAD>
 <TITLE>PROPOSAL FOR INSURANCE OF MONEY</TITLE>
</HEAD>

<BODY>

<CFINCLUDE TEMPLATE="clicoheader.cfm">

<CENTER>

<H1><U>CLICO</U></H1>

<H3>INTERNATIONAL<BR>
GENERAL INSURANCE<BR>
LIMITED</H3>

<H2>PROPOSAL FOR INSURANCE OF MONEY</H2>

<B>i.e. Cash, Bank and Currency Notes, Cheques, Money Orders, Postal
Orders, and Current Postage Stamps all belonging to the insured or
for which he has accepted responsability</B>

</CENTER>

<FORM ACTION="clicomoninsformaction.cfm" METHOD="POST">

<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=4>

<TR>
<TH COLSPAN=4>
<U><H3>Name & Contact Information of Applicants</H3></U>
</TH>
</TR>

<P>

<TR>
<TD>
<B>First name:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustFirstName" SIZE="30"
 MAXLENGTH="30" VALUE="#CustFirstName#">
</TD>
<TD>
<B>Middle Initial(s):</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustMiddleInit" SIZE="2"
 MAXLENGTH="1" VALUE="#CustMiddleInit#">
</TD>
</TR>

<TR>
<TD>
<B>Last name:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustLastName" SIZE="30"
 MAXLENGTH="30" VALUE="#CustLastName#">
</TD>
</TR>

<TR>
<TD>
<B>Address1:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustAddress1" SIZE="30"
 MAXLENGTH="50" VALUE="#CustAddress1#">
</TD>
<TD>
<B>Address2:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustAddress2" SIZE="30"
 MAXLENGTH="50" VALUE="#CustAddress2#">
</TD>
</TR>

<TR>
<TD>
<B>City:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustCity" SIZE="30"
 MAXLENGTH="40" VALUE="#CustCity#">
</TD>
<TD>
<B>Parish:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustParish" SIZE="30"
 MAXLENGTH="50" VALUE="#CustParish#">
</TD>
</TR>

<TR>
<TD>
<B>Country:</B>
</TD>
<TD>
<SELECT
NAME="Country"><OPTION>Afghanistan<OPTION>Albania<OPTION>Algeria<OPTION>Amer
ican
Samoa<OPTION>Andorra<OPTION>Angola<OPTION>Anguilla<OPTION>Antarctica<OPTION>
Antigua and
Barbuda<OPTION>Argentina<OPTION>Armenia<OPTION>Aruba<OPTION>Australia<OPTION
>Austria<OPTION>Azerbaijan<OPTION>Bahamas<OPTION>Bahrain<OPTION>Bangladesh<O
PTION
SELECTED>Barbados<OPTION>Belarus<OPTION>Belgium<OPTION>Belize<OPTION>Benin<O
PTION>Bermuda<OPTION>Bhutan<OPTION>Bolivia<OPTION>Bosnia and
Herzegovina<OPTION>Botswana<OPTION>Bouvet
Island<OPTION>Brazil<OPTION>British Indian Ocean Territory<OPTION>Brunei
Darussalam<OPTION>Bulgaria<OPTION>Burkina
Faso<OPTION>Burundi<OPTION>Cambodia<OPTION>Cameroon<OPTION>Canada<OPTION>Cap
e Verde<OPTION>Cayman Islands<OPTION>Central African
Republic<OPTION>Chad<OPTION>Chile<OPTION>China<OPTION>Christmas
Island<OPTION>Cocos (Keeling
Islands)<OPTION>Colombia<OPTION>Comoros<OPTION>Congo<OPTION>Cook
Islands<OPTION>Costa Rica<OPTION>Cote D'Ivoire (Ivory Coast)<OPTION>Croat!
ia (Hrvatska)<OPTION>Cuba<OPTION>Cyprus<OPTION>Czech
Republic<OPTION>Denmark<OPTION>Djibouti<OPTION>Dominica<OPTION>Dominican
Republic<OPTION>East Timor<OPTION>Ecuador<OPTION>Egypt<OPTION>El
Salvador<OPTION>Equatorial
Guinea<OPTION>Eritrea<OPTION>Estonia<OPTION>Ethiopia<OPTION>Falkland Islands
(Malvinas)<OPTION>Faroe
Islands<OPTION>Fiji<OPTION>Finland<OPTION>France<OPTION>France,
Metropolitan<OPTION>French Guiana<OPTION>French Polynesia<OPTION>French
Southern
Territories<OPTION>Gabon<OPTION>Gambia<OPTION>Georgia<OPTION>Germany<OPTION>
Ghana<OPTION>Gibraltar<OPTION>Greece<OPTION>Greenland<OPTION>Grenada<OPTION>
Guadeloupe<OPTION>Guam<OPTION>Guatemala<OPTION>Guinea<OPTION>Guinea-Bissau<O
PTION>Guyana<OPTION>Haiti<OPTION>Heard and McDonald
Islands<OPTION>Honduras<OPTION>Hong
Kong<OPTION>Hungary<OPTION>Iceland<OPTION>India<OPTION>Indonesia<OPTION>Iran
<OPTION>Iraq<OPTION>Ireland<OPTION>Israel<OPTION>Italy<OPTION>Jamaica<OPTION
>Japan<OPTION>Jordan<OPTION>Kazakhstan<OPTION>Kenya<OPTIO!
N>Kiribati<OPTION>Korea (North)<OPTION>Korea
(South)<OPTION>Kuwait<OPTION>Kyrgyzstan<OPTION>Laos<OPTION>Latvia<OPTION>Leb
anon<OPTION>Lesotho<OPTION>Liberia<OPTION>Libya<OPTION>Liechtenstein<OPTION>
Lithuania<OPTION>Luxembourg<OPTION>Macau<OPTION>Macedonia<OPTION>Madagascar<
OPTION>Malawi<OPTION>Malaysia<OPTION>Maldives<OPTION>Mali<OPTION>Malta<OPTIO
N>Marshall
Islands<OPTION>Martinique<OPTION>Mauritania<OPTION>Mauritius<OPTION>Mayotte<
OPTION>Mexico<OPTION>Micronesia<OPTION>Moldova<OPTION>Monaco<OPTION>Mongolia
<OPTION>Montserrat<OPTION>Morocco<OPTION>Mozambique<OPTION>Myanmar<OPTION>Na
mibia<OPTION>Nauru<OPTION>Nepal<OPTION>Netherlands<OPTION>Netherlands
Antilles<OPTION>New Caledonia<OPTION>New
Zealand<OPTION>Nicaragua<OPTION>Niger<OPTION>Nigeria<OPTION>Niue<OPTION>Norf
olk Island<OPTION>Northern Mariana
Islands<OPTION>Norway<OPTION>Oman<OPTION>Pakistan<OPTION>Palau<OPTION>Panama
<OPTION>Papua New
Guinea<OPTION>Paraguay<OPTION>Peru<OPTION>Philippines<OPTION>Pitcairn<OPTION
>Poland<O!
PTION>Portugal<OPTION>Puerto
Rico<OPTION>Qatar<OPTION>Reunion<OPTION>Romania<OPTION>Russian
Federation<OPTION>Rwanda<OPTION>S. Georgia and S. Sandwich
Isls.<OPTION>Saint Kitts and Nevis<OPTION>Saint Lucia<OPTION>Saint Vincent
and The Grenadines<OPTION>Samoa<OPTION>San Marino<OPTION>Sao Tome and
Principe<OPTION>Saudi Arabia<OPTION>Senegal<OPTION>Seychelles<OPTION>Sierra
Leone<OPTION>Singapore<OPTION>Slovak Republic<OPTION>Slovenia<OPTION>Solomon
Islands<OPTION>Somalia<OPTION>South Africa<OPTION>Spain<OPTION>Sri
Lanka<OPTION>St. Helena<OPTION>St. Pierre and
Miquelon<OPTION>Sudan<OPTION>Suriname<OPTION>Svalbard and Jan Mayen
Islands<OPTION>Swaziland<OPTION>Sweden<OPTION>Switzerland<OPTION>Syria<OPTIO
N>Taiwan<OPTION>Tajikistan<OPTION>Tanzania<OPTION>Thailand<OPTION>Togo<OPTIO
N>Tokelau<OPTION>Tonga<OPTION>Trinidad and
Tobago<OPTION>Tunisia<OPTION>Turkey<OPTION>Turkmenistan<OPTION>Turks and
Caicos Islands<OPTION>Tuvalu<OPTION>US Minor Outlying
Islands<OPTION>Uganda<OPTION>Ukraine<!
OPTION>United Arab Emirates<OPTION>United Kingdom<OPTION>United
States<OPTION>Uruguay<OPTION>Uzbekistan<OPTION>Vanuatu<OPTION>Vatican City
State (Holy See)<OPTION>Venezuela<OPTION>Viet Nam<OPTION>Virgin Islands
(British)<OPTION>Virgin Islands (US)<OPTION>Wallis and Futuna
Islands<OPTION>Western
Sahara<OPTION>Yemen<OPTION>Yugoslavia<OPTION>Zaire<OPTION>Zambia<OPTION>Zimb
abwe</SELECT>
</TD>
</TR>

<TR>
<TD>
<B>Home Phone Number:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustHomePhone" SIZE="20"
 MAXLENGTH="20" VALUE="#CustHomePhone#">
</TD>
<TD>
<B>Work Phone Number:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustWorkPhone" SIZE="20"
 MAXLENGTH="20" VALUE="#CustWorkPhone#">
</TD>
</TR>

<TR>
<TD>
<B>Home Phone Number:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustEmail" SIZE="30"
 MAXLENGTH="30" VALUE="#CustEmail#">
</TD>
</TR>

<TR>
<TD>
<B>Trade or Business:</B>
</TD>
<TD>
<TEXTAREA NAME="CustBusiness" ROWS=5 COLS=10></TEXTAREA>
</TD>
</TR>

</TABLE>

<P>

<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=4>

<TR>
<TH COLSPAN=4>
<U><H3>Details of Premises</H3></U>
</TH>
</TR>

<TR>
<TH COLSPAN=4>
<H4>Address(es) where money is to be insured</H4>
</TH>
</TR>

<TR>
<TD>
<B>Premises 1:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="PremAddress1" SIZE="30"
 MAXLENGTH="50" VALUE="#PremAddress1#">
</TD>
<TD>
<B>Premises 2:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="PremAddress2" SIZE="30"
 MAXLENGTH="50" VALUE="#PremAddress2#">
</TD>
</TR>

<TR>
<TD>
<B>City:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="PremCity" SIZE="30"
 MAXLENGTH="40" VALUE="#PremCity#">
</TD>
<TD>
<B>Parish:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="PremParish" SIZE="30"
 MAXLENGTH="50" VALUE="#PremParish#">
</TD>
</TR>

<TR>
<TD>
<B>Are the premises occupied at night?:</B>
</TD>
<TD>
<INPUT TYPE="checkbox" NAME="PremNight" VALUE="Yes">
</TD>
<TD>
<B>If so, by whom?:</B>
</TD>
<TD>
<TEXTAREA NAME="PremNightName"
          COLS="22"
          ROWS="5">"PremNightName"</TEXTAREA>
</TD>
</TR>

<TR>
<TH COLSPAN=4>
<H4>Details of transits to and from the bank or post office to the
premises</H4>
</TH>
</TR>

<TR>
<TD>
<B>How far is the bank or post office from the premises?</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="PremDist" SIZE="10"
 MAXLENGTH="10" VALUE="#PremDist#">miles
</TD>
<TD>
<B>How is the journey made, e.g. on foot or by public or
private conveyance?</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="PremHowJourney" SIZE="30"
 MAXLENGTH="30" VALUE="#PremHowJourney#">
</TD>
</TR>

<TR>
<TD>
<B>What is the number of adult males in charge of
each journey?</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="PremMaleNumber" SIZE="2"
 MAXLENGTH="2" VALUE="#PremMaleNumber#">
</TD>
<TD>
<B>What special precautions are taken?</B>
</TD>
<TD>
<TEXTAREA NAME="PremPrecaution"
          COLS="22"
          ROWS="5">#PremPrecaution#</TEXTAREA>
</TD>
</TR>

<TR>
<TH COLSPAN=4>
<U><H3>Miscellaneous information concerning the premises and
the monies to be insured</H3></U>
</TH>
</TR>

<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=4>

<TR>
<TH COLSPAN=4>
<U><H3>Name & Contact Information of Applicants</H3></U>
</TH>
</TR>

<P>

<!---Please ignore this
<TR>
<TD>
<B>Sum to be insured any one loss in respect of crossed cheques,
crossed money orders and crossed postal orders:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustFirstName" SIZE="20"
 MAXLENGTH="20" VALUE="#CustFirstName#">
</TD>
<TD>
<B>Middle Initial(s):</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustMiddleInit" SIZE="2"
 MAXLENGTH="1" VALUE="#CustMiddleInit#">
</TD>
</TR>--->

</TABLE>

<!---Please ignore this
<P>
<TR>
<TD>
<B>Username:</B>
</TD>
<TD>
<INPUT TYPE="text" NAME="CustUserName" SIZE="30"
 MAXLENGTH="30" VALUE="#CustUserName#">
</TD>
<TD>
<B>Password:</B>
</TD>
<TD>
<INPUT TYPE="password" NAME="CustPassword" SIZE="30"
 MAXLENGTH="20" VALUE="#CustPassword#">
</TD>
</TR>
--->


</FORM>

</BODY>

</HTML>

</CFOUTPUT>


---
Hubert Earl

ICQ#: 16199853
AIM: hubertfme

My Jamaican Art, Craft & More Online Store:
http://www.angelfire.com/ny/hearl/link_page_on_angelfire.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to