The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
Question about code logic and radio buttons in cfform
Discuss Question about code logic and radio buttons in cfform in the ColdFusion Development forum on Dev Shed. Question about code logic and radio buttons in cfform ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 27th, 2012, 04:33 PM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 2
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
|

June 27th, 2012, 08:13 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
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.
|

June 28th, 2012, 02:06 PM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 2
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>
|

June 28th, 2012, 02:32 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|