Your message is a reply to anothers post and is more than 100 lines of text. Unless you are a major writer, your probably adding a lot of the previous replies. Please trim your posts when replying. Thank you.

I usually show a list of records with normal links next to them for "EDIT" or "DELETE" and an "ADD" link on the page aswell.
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
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to