Default values in form
I'm building a form for my office that submits info to a database. I'd like to use the same form to add new info and edit existing info. I also want the form to retain data once it's sumitted (i.e. if the user clicks submit and there's a blank field required, the form is re-loaded with the data retained.
I am not allowed to use javascript (agency rule).
I started off with something like this for each field:
<cfinput type="text" name="title" value="#FORM.title#" />
This is fine, but then I added the edit option. A user pics an entry on a preceding page that passes an id number in the URL (ex: form.cfm?edit=32) to the form.
When URL.edit has a value of other than zero (the assigned cfparam default), it triggers a query that grabs the data out of the database. I want this data to populate the form, so I tried this:
<cfinput type="text" name="title" value="#iif(URL.edit eq 0,DE(FORM.title),DE(queryname.title))#" />
This works perfectly if the query is run, but I get an error when I load the blank form:
Element TITLE is undefined in QUERYNAME.
I'm basically trying to make the default form value blank if the form is loaded from scratch, make it the previous form values if the form is re-loaded after submitting, or and make it use the query if a URL param is passed.
Is there any way to make this work? I don't want to have to write multiple versions of the form.
