ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 27th, 2012, 04:33 PM
rob53 rob53 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 2 rob53 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 46 sec
Reputation Power: 0
Question about code logic and radio buttons in cfform

hi, I'm relatively new to Coldfusion and I have a problem I can't quite get my head around although this may be quite simple for those more experienced...

I have a form - two of the fields I collect are the date and time (entered by user) and this gets entered into DateOf and TimeOf fields in my Access database.

I also want the user to have the option of NOT entering the date and time manually in the form text boxes but also have the form submit hidden date and time as (Now()), IF manually not entered in form...

This is an either/or situation - the user can entered past dates/times in the text boxes OR the can leave boxes blank and the hidden fields will pass date/time as (Now()).

My question is this - since both options get entered into same Database fields - DateOf and TimeOf, how best do I have user select either option? I was thinking a radio button selection on the form where option 1 - hidden date/time is passed as Now() to Db or option 2 - manually entered text boxes are passed to Db.

I need a situation where both are not passed, only one or the other but I can't figure out the correct logic to do this with radio buttons. Any help or suggestions of how to best accomplish this would be greatly appreciated.
cheers, rob

Reply With Quote
  #2  
Old June 27th, 2012, 08:13 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
Why use hidden form fields? I would just create the date and time on the server if the values passed in the form are empty, and use those in the database insert.

Reply With Quote
  #3  
Old June 28th, 2012, 02:06 PM
rob53 rob53 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 2 rob53 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 46 sec
Reputation Power: 0
Thanks Kiteless, you rock! - I knew there had to be a simpler way - just couldn't see it! This worked like a charm on the form action page -

<cfif EditMode>
<cfparam name="FORM.ID" type="integer">
<cfupdate (details deleted etc) ...>

<!--- ADD MODE, if NO ID is passed in the form - assume this is a new addition --->
<cfelse>
<!--- now we check to see if date/time fields in form are empty or not --->
<cfif Form.DateOf IS '' OR Form.Timestamped IS ''>
<cfset DateNow=#createODBCDate(Now())#>
<cfset TimestampedNow=#createODBCDateTime(Now())#>
<!--- dates and time need to be inserted with a query else time doesn't work in DB --->
<cfquery name="qAddInfo" datasource="#DataSource#">
INSERT INTO MainTable
(DateOf,Timestamped)
VALUES
(#DateNow#,#TimestampedNow#)
</cfquery>
<!--- ... if the date/time fields in the Form are NOT empty, we use those ... --->
<cfelse>
<cfquery name="qAddInfo" datasource="#DataSource#">
INSERT INTO MainTable
(DateOf,Timestamped)
VALUES
(#Form.DateOf#,#Form.Timestamped#)
</cfquery>
</cfif>

Reply With Quote
  #4  
Old June 28th, 2012, 02:32 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
Hmm, well first, I would never use cfupdate, but that's just me.

Second, you don't need to do this as separate queries:

Code:
<cfif not Len( Trim( form.DateOf )>
	<cfset form.DateOf = CreateODBCDate( Now() ) />
</cfif>
<cfif not Len( Trim( form.Timestamped )>
	<cfset form.Timestamped = CreateODBCDateTime( Now() ) />
</cfif>

<cfquery name="qAddInfo" datasource="#DataSource#">
INSERT INTO MainTable
(DateOf,Timestamped)
VALUES
(#Form.DateOf#,#Form.Timestamped#)
</cfquery>

Third, you REALLY should be using cfqueryparam for ALL user-supplied values, to prevent SQL injection exploits.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Question about code logic and radio buttons in cfform

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap