RE: passing empty form field entry

2003-10-17 Thread Pascal Peters
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]




RE: passing empty form field entry

2003-10-17 Thread Tim Laureska
Yes Pascal... thanks, the 2nd possibility is where I was at... I was
trying to insert an empty string (no value) into a number field and
experienced the error ... I would have never known to use the code you
show (cfsqltype=CF_SQL_NUMERIC)... Is this code referenced/explained
anywhere on the web?

I did a simple
cfparam name=exp_years default=0 in the receing template and that
seemed to work

But I think your method is more upfront and technically correct

Thanks
Tim the novice

-Original Message-
From: Pascal Peters [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 17, 2003 3:27 AM
To: CF-Talk
Subject: RE: passing empty form field entry

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]




RE: passing empty form field entry

2003-10-17 Thread Pascal Peters
Just type cfqueryparam in Google

	-Oorspronkelijk bericht- 
	Van: Tim Laureska [mailto:[EMAIL PROTECTED] 
	Verzonden: vr 17/10/2003 13:27 
	Aan: CF-Talk 
	CC: 
	Onderwerp: RE: passing empty form field entry
	
	
	Yes Pascal... thanks, the 2nd possibility is where I was at... I was
	trying to insert an empty string (no value) into a number field and
	experienced the error ... I would have never known to use the code you
	show (cfsqltype=CF_SQL_NUMERIC)... Is this code referenced/explained
	anywhere on the web?
	
	


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




RE: passing empty form field entry

2003-10-17 Thread Charlie Griefer
http://www.macromedia.com/devnet/mx/coldfusion/articles/cfqueryparam.html

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

Yes Pascal... thanks, the 2nd possibility is where I was at... I was
trying to insert an empty string (no value) into a number field and
experienced the error ... I would have never known to use the code you
show (cfsqltype=CF_SQL_NUMERIC)... Is this code referenced/explained
anywhere on the web?



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




RE: passing empty form field entry

2003-10-16 Thread Matthew Walker
The standard way is a cfparam.

-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:21 a.m.
To: CF-Talk
Subject: 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]




RE: passing empty form field entry

2003-10-16 Thread Tim Laureska
Where do you set the cfparam?In the receiving template such as
cfparam name=exp_months default=

I've always struggled with CFPARAM

-Original Message-
From: Matthew Walker [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 16, 2003 7:36 PM
To: CF-Talk
Subject: RE: passing empty form field entry

The standard way is a cfparam.

-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:21 a.m.
To: CF-Talk
Subject: 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]




RE: passing empty form field entry

2003-10-16 Thread Matthew Walker
Basically cfparam is a way of saying let's just make sure this variable
exists as we're relying on it. You can also also do other things with it
but that's the basic deal. 

Here's a custom tag I knocked together this morning which is similar to
cfparam but a bit more featureful. You call itlike this:

cf_param name=attributes.chunksize type=numeric default=10 min=1
max=100

Instead of throwing an error it simply fixes up the data. It's not very
tested but feel free to play. There're probably better versions around.



cfparam name=attributes.name type=string

cfparam name=attributes.type type=string default=

cfparam name=attributes.min default=

cfparam name=attributes.max default=

cfif structkeyexists(caller, attributes.name)

cfset value = caller[attributes.name]

cfelseif structkeyexists(attributes, default)

cfset value = attributes.default

cfelse

cfset value = 

/cfif

cfif attributes.type eq numeric

cfset value = val(value)

/cfif

cfparam name=value type=#attributes.type#

cfif attributes.type eq numeric

cfif len(attributes.min)

cfif value lt attributes.min

cfset value = attributes.min

/cfif

/cfif

cfif len(attributes.max)

cfif value gt attributes.max

cfset value = attributes.max

/cfif

/cfif



/cfif

cfset caller[attributes.name] = value





-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:49 a.m.
To: CF-Talk
Subject: RE: passing empty form field entry

Where do you set the cfparam?In the receiving template such as
cfparam name=exp_months default=

I've always struggled with CFPARAM

-Original Message-
From: Matthew Walker [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 16, 2003 7:36 PM
To: CF-Talk
Subject: RE: passing empty form field entry

The standard way is a cfparam.

-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:21 a.m.
To: CF-Talk
Subject: 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]




RE: passing empty form field entry

2003-10-16 Thread Tim Laureska
Thanks Matthew... so if a form field entry is left blank, the variable
is not passed to the receiving template?

-Original Message-
From: Matthew Walker [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 16, 2003 7:54 PM
To: CF-Talk
Subject: RE: passing empty form field entry

Basically cfparam is a way of saying let's just make sure this variable
exists as we're relying on it. You can also also do other things with
it
but that's the basic deal. 

Here's a custom tag I knocked together this morning which is similar to
cfparam but a bit more featureful. You call itlike this:

cf_param name=attributes.chunksize type=numeric default=10
min=1
max=100

Instead of throwing an error it simply fixes up the data. It's not very
tested but feel free to play. There're probably better versions around.



cfparam name=attributes.name type=string

cfparam name=attributes.type type=string default=

cfparam name=attributes.min default=

cfparam name=attributes.max default=

cfif structkeyexists(caller, attributes.name)

cfset value = caller[attributes.name]

cfelseif structkeyexists(attributes, default)

cfset value = attributes.default

cfelse

cfset value = 

/cfif

cfif attributes.type eq numeric

cfset value = val(value)

/cfif

cfparam name=value type=#attributes.type#

cfif attributes.type eq numeric

cfif len(attributes.min)

cfif value lt attributes.min

cfset value = attributes.min

/cfif

/cfif

cfif len(attributes.max)

cfif value gt attributes.max

cfset value = attributes.max

/cfif

/cfif



/cfif

cfset caller[attributes.name] = value





-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:49 a.m.
To: CF-Talk
Subject: RE: passing empty form field entry

Where do you set the cfparam?In the receiving template such as
cfparam name=exp_months default=

I've always struggled with CFPARAM

-Original Message-
From: Matthew Walker [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 16, 2003 7:36 PM
To: CF-Talk
Subject: RE: passing empty form field entry

The standard way is a cfparam.

-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:21 a.m.
To: CF-Talk
Subject: 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]




RE: passing empty form field entry

2003-10-16 Thread Matthew Walker
Generally it is. With radio buttons and checkboxes you'll probably find it
isn't.

However, it's generally considered good practice to cfparam all of the form
variables. 



-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 12:03 p.m.
To: CF-Talk
Subject: RE: passing empty form field entry

Thanks Matthew... so if a form field entry is left blank, the variable
is not passed to the receiving template?

-Original Message-
From: Matthew Walker [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 16, 2003 7:54 PM
To: CF-Talk
Subject: RE: passing empty form field entry

Basically cfparam is a way of saying let's just make sure this variable
exists as we're relying on it. You can also also do other things with
it
but that's the basic deal. 

Here's a custom tag I knocked together this morning which is similar to
cfparam but a bit more featureful. You call itlike this:

cf_param name=attributes.chunksize type=numeric default=10
min=1
max=100

Instead of throwing an error it simply fixes up the data. It's not very
tested but feel free to play. There're probably better versions around.

cfparam name=attributes.name type=string

cfparam name=attributes.type type=string default=

cfparam name=attributes.min default=

cfparam name=attributes.max default=

cfif structkeyexists(caller, attributes.name)

cfset value = caller[attributes.name]

cfelseif structkeyexists(attributes, default)

cfset value = attributes.default

cfelse

cfset value = 

/cfif

cfif attributes.type eq numeric

cfset value = val(value)

/cfif

cfparam name=value type=#attributes.type#

cfif attributes.type eq numeric

cfif len(attributes.min)

cfif value lt attributes.min

cfset value = attributes.min

/cfif

/cfif

cfif len(attributes.max)

cfif value gt attributes.max

cfset value = attributes.max

/cfif

/cfif



/cfif

cfset caller[attributes.name] = value



-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:49 a.m.
To: CF-Talk
Subject: RE: passing empty form field entry

Where do you set the cfparam?In the receiving template such as
cfparam name=exp_months default=

I've always struggled with CFPARAM

-Original Message-
From: Matthew Walker [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 16, 2003 7:36 PM
To: CF-Talk
Subject: RE: passing empty form field entry

The standard way is a cfparam.

-Original Message-
From: Tim Laureska [mailto:[EMAIL PROTECTED] 
Sent: Friday, 17 October 2003 11:21 a.m.
To: CF-Talk
Subject: 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]