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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining Forms

Status
Not open for further replies.

RadioX

IS-IT--Management
May 15, 2001
145
US
I know there has got to be a better way to do this then what I am doing now. So I need to broaden my horizons.

Basically I have a from where you can enter in user information (name, address, city, state, etc) and then I havea form where you can edit this information.

Is there a simple way to combine these so I have only one form instead of one for a new insert and one for an edit.

I know this is prolly simple but I have been doing it the "old" way for way to long now.

Thanks
Ron
 
you CAN use one page to do both insert and edit if you want but in my experience i've found it easier to have the two seperate.

After you run all the checks you'll need in each form field to either populate or leave blank then either insert or update... i think you'll agree.

just my opinion.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Probably you have a link/button/selection where you have to select what you want to do, either insert or update.

let's say your template is called addEditUserForm.cfm

when you click on the link insert pass a uniqueID ( you gotta have a UniqueID for the user) like 0.
If you select update then pass the actual user ID.

on the header of the addEditUserForm.cfm grab the uniqueID
and use a simple conditional.
(1)If the ID is other than 0 try to select data from your DB.
(1.1)If the query returns nothing or more than one value, then show an error (somebody is trying to fool you)
(1.2) If the query returns one and only one value then jump to the Form section and have all your values equal to the values coming from the database
(2) If the user ID is zero then show your form but with no initial values to display in the boxes.
(3) In any case have a hidden variable in your form holding your uniqueID no matter what value it has.
(4) Your form action page could be the same but if you want you could have one for insert and one for update (your call).
(5) if you have only one action page (let's say addEditUserAction.cfm) you can use that hidden value and again use a conditional. If the user ID is 0 then use an Insert of all the values from the form. If the userID is different from zero use and Update based on the hidden value.

hope that helps or at least gives you ideas.

I'm not considering validation on the server and/or client side, because I assume you already know about this.

If not you could always post back.

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top