the link will pass a url variable that holds the records ID in the database table ... in this example it is url.RecordID
EDIT and DELETE would pass the url variable, ADD would not
<!--- This is one form used for adding or editing records --->
<cfparam name="url.recordid" default="0">
<!--- get a record that matches url.recordid --->
<cfquery name="GetRecords" datasource="#MYDSN#">
select * from table where RecordID = #val(url.recordid)#
</cfquery>
<!--- if there IS a record that matches url.recordid then this is an EDIT form, else it is an ADD form --->
<cfif GetRecords.RecordCount is 0>
<cfset ButtonText = "ADD">
<cfelse>
<cfset ButtonText = "EDIT">
</cfif>
<!--- if the form variables dont already exist, set params for them to whatever record was found in the database. If there was one... else these params default to nothing --->
<cfparam name="formRecordID" default="#GetRecords.RecordID#">
<cfparam name="formField1" default="#GetRecords.Field1#">
<cfparam name="formField2" default="#GetRecords.Field2#">
<cfparam name="formField3" default="#GetRecords.Field3#">
<cfparam name="formField4" default="#GetRecords.Field4#">
<!--- make sure the action="" keeps passing the url.recordid along --->
<form name="myform" action="" method="Post">
<input type="hidden" name="RecordID" value="#val(Form.RecordID)#">
<!--- now each form field can be its own value and will remember what was in it when submitted --->
Field1: <input type="text" name="Field1" value="#Form.FIeld1#"><br>
Field2: <input type="text" name="Field2" value="#Form.FIeld2#"><br>
Field3: <input type="text" name="Field3" value="#Form.FIeld3#"><br>
Field4: <input type="text" name="Field4" value="#Form.FIeld4#"><br>
<input type="submit" name="#ButtonText#" value="#ButtonText# Record">
</form>
<!--- this will either come up empty with a button called "ADD" to submit it or full of a record in the database with a button called "EDIT" to submit with --->
<!--- on your action page all you have to do is something like ....
<cfif isdefined('form.add')>
VALIDATE FORM AND ADD RECORD HERE
<cfelseif isdefined('form.edit')>
VALIDATE AND EDIT RECORD HERE
<cfelseif isdefined('url.delete')>
<cfparam name="url.recordid" default="0">
SEE IF THERE IS A RECORD THAT MATCHES URL.RECORDID
IF SO, DELETE IT
</cfif>
--->
----- Original Message -----
From: dave
To: CF-Talk
Sent: Tuesday, August 17, 2004 1:47 AM
Subject: Re: keeping form data during server-side validation
flash baby flash!!! ;)
can set them as variables
rather boring to code all that cfif stuff though
---------- Original Message ----------------------------------
From: Roberto Perez <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
Date: Mon, 16 Aug 2004 02:30:03 -0400
>Hi all,
>
>Maybe this topic has been covered before, but I'm not sure what keywords
>I'd use in Google or in the list archives to find related messages.
>
>I want to validate data from a form (missing fields, password field and
>re-enter password field, etc.), and reload the form page with an error
>message. However, when I do this I lose all data entered, and the user has
>to reenter everything again. If I display an empty page with a message like
>"use the back button to go back to the form and correct the information",
>by using the back button in the browsers users do get the fields populated.
>
>Do you have specific instructions/steps to get that effect (going back to
>pre-populated fields) using CF (instead of using the back button in the
>browser)?
>
>Another option would be to do the validation client-side with _javascript_,
>but I'd rather do it server side on the browser.
>
>Thanks,
>
>Roberto Perez
>[EMAIL PROTECTED]
>
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]