First of all: if the field is a radio, checkbox or multiple select, you use <cfparam to set a default value on the action page.
<cfparam name="form.myfield" default="">


Then in your query you have 2 possibilities:
1. The field is a text field in the db (char, varchar, ...). You can just insert the empty string. If you want to insert a NULL or a default value: see 2
2. The field is not a text field. Then you have problems inserting the empty string because it doesn't match your datatype and it will throw an sql error. The solution is usually to insert NULL instead and the way to do that is <cfqueryparam (and of course you are already using it ;-) ):


INSERT INTO TBL(field)
VALUES (<cfqueryparam cfsqltype="CF_SQL_NUMERIC" value="#form.myfield#" null="#YesNoFormat(Len(form.myfield))#">)


If you want a default value inserted, you can change the value when you do your server side validation:
<cfif NOT Len(form.myfield)> <!--- or any other validation --->
    <cfset form.myfield = "default_value">
</cfif>


Pascal

-----Oorspronkelijk bericht-----
Van: Tim Laureska [mailto:[EMAIL PROTECTED]
Verzonden: vr 17/10/2003 1:21
Aan: CF-Talk
CC:
Onderwerp: passing empty form field entry


If a web site visitor completes a form without entering data in a field
(which in this case may be OK), how do you set up the coding for
inserting that "blank" entry into a database (or ignoring that field).  

If I include the field in the SQL insert statement, I get an error
"resolving parameter"

I'm trying to avoid a bunch of CFIF statements (ie. CFIF "field EQ '',
then such and such CFELSE such and such)

TIA
Tim



[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to