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

Multi Use Forms

Status
Not open for further replies.

bluesauceuk

Programmer
Jan 1, 2001
73
GB
Hello,

Just wondering if anyone knows how to make my application easier to code.

I have just looked at it and I have action pages for all the things I want to do. One for add, one for amend and another for deleting a record.

I've looked into fusebox - and I find it too dificult for now (given the timescale).

Could someone show me how to make a master form processor page for say a product detail page.

The table is

=================
productid (unqiue)
description
price
notes
keywords
dateadded
==================

I guess how you would do it is to... if there is no productid passed - this is a brand new entry, if there is an id then it's a amend - and if it is delete - "are you sure?" before the row is binned?

Could someone show me how it is done?

Kindest Regards


Mark :)
 
You could easily combine all of the action pages into one. Without knowing anything about your application, here is just a brief summary of one way you could do it.
Code:
<cfif NOT IsDefined("Form.productid")>
   ....Code to Insert a new record here....
<cfelse>
  <cfif Form.WhatToDo EQ "Update">
      ....Code to Update a record here....
  <cfelseif Form.WhatToDo EQ "Delete">
      ....Code to Delete a record here....
  </cfif>
<cfif>
Notice that I am using a variable called "Form.WhatToDo" in my CFIF statements. You can create a hidden form field in your update and delete forms called "WhatToDo" (or whatever you want to name it) and set the value to either "Delete" or "Update" for each form. When this field is passed to the action page, the CFIF statements will take the appropriate action. For that matter, you could also put a "WhatToDo" hidden field in your Insert form, and just change the above code to be:
Code:
<cfif Form.WhatToDo EQ "Insert">
   ....Code to Insert a new record here....
<cfelseif Form.WhatToDo EQ "Update">
   ....Code to Update a record here....
<cfelseif Form.WhatToDo EQ "Delete">
   ....Code to Delete a record here....
<cfif>
Now, this doesn't have any kind of "are you sure?" verification for the delete.

As I said, this is a very basic example, but it should get you started in the right direction. There are several other (some more complex) ways to get this done.




Hope This Helps!

Ecobb

&quot;My work is a game, a very serious game.&quot; - M.C. Escher
 
Thanks,

So if this was products.cfm?action=view we could display the rows...

1 nice jug 10.00 this is a jug jug, vase 25/01/99 full view edit delete

then have a link to products.cfm?action=add

Then are all the forms kept in the action page?

Mark
 
The second code is better because it requires no mods..

If you use:

Code:
<cfif NOT IsDefined("Form.productid")>
   ....Code to Insert a new record here....
<cfelse>
  <cfif Form.WhatToDo EQ "Update">
      ....Code to Update a record here....
  <cfelseif Form.WhatToDo EQ "Delete">
      ....Code to Delete a record here....
  </cfif>
<cfif>

You'll need to say something like

Code:
<cfif parameterExists(form.SubmitButtonNameHere)>
  <cfif NOT IsDefined("Form.productid")>
     ....Code to Insert a new record here....
  <cfelse>
    <cfif Form.WhatToDo EQ "Update">
        ....Code to Update a record here....
    <cfelseif Form.WhatToDo EQ "Delete">
        ....Code to Delete a record here....
    </cfif>
  <cfif>
</cfif>

otherwise if someone gets to the page by accident, sometimes web spiders hit the wrong page or someone being malicious.. Going directly to the page will try to insert a record.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Could I do this with CFCs - I would like to a cfc that does all the querying and adding a deleting..

Is this possible..

Apart from the macromedia website - does anyone know of tutorials into how to9 use cfcs with forms etc..

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top