ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 January 22nd, 2004, 02:36 PM
vinyl's Avatar
vinyl vinyl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 236 vinyl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 21 sec
Reputation Power: 5
Arrow how to assign 'not defined' to all undefined form values??

I have one BIG form and I have a .cfm mail processor as the form action - I used <CFMAIL> but ColdFusion always generates an error if some form field is left blank.

Now, I could code this for each field

<cfif IsDefined('form.fieldname')>
<cfoutput>
#form.fieldname#
<cfoutput>
<cfelse>
Field left blank.
<cfif>

but I have so many fields and it would take me too long to do that for each

Can somebody tell me if there's some loop which will check all form fields (without actual code for each field) and if it's blank, just puting "undefined" string as a content of it, so that I dont get those errors when somebody leave field blank? After checking them all in a loop and assigning "undefined" as their value, I could preform my CFMAIL function without problems.

This is PHP code for the thing I want, but I don't know ColdFusion enough to write that in it:

PHP Code:
while (list ($variable$value) = each ($HTTP_POST_VARS))
{
if(
$value == "" OR !isset($value))
{
$variable "undefined";
}



Thanks!

Reply With Quote
  #2  
Old January 22nd, 2004, 03:51 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
You must be talking about checkbox form elements, because no other form element would be showing up as undefined if the field was empty. It would just be an empty string. You can check for that like this:

<cfif not len( trim( form.someField ) )>
Code to fire if form element is empty.
</cfif>

So no, there is no way for the target page to "know" about any checkbox elements that were not submitted, because they aren't sent to the target page at all. You'd have to manually code isDefined() blocks for each checkbox element.

In other words, if the user submits a form and there is a text field on that form that they didn't fill out, the target page gets that variable, but it is an empty string. But if the user submits a form and there is an unchecked check box on that form, the variable doesn't exist at all on the target page. I believe this is how it works for any application server, not just CF. Unchecked check boxes aren't sent in the HTTP header at all.

Reply With Quote
  #3  
Old January 23rd, 2004, 06:17 AM
vinyl's Avatar
vinyl vinyl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 236 vinyl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 21 sec
Reputation Power: 5
you were right, checkboxes and radio buttons aren't passed in headers at all, I had to use IsDefined so many times like this:

...

<cfif Not IsDefined('form.liver')>
<cfset form.liver = "FIELD LEFT BLANK">
</cfif>


<cfif Not IsDefined('form.alergija')>
<cfset form.alergija = "FIELD LEFT BLANK">
</cfif>


<cfif Not IsDefined('form.choja')>
<cfset form.choja = "FIELD LEFT BLANK">
</cfif>

...

Thank you once again, are you the only one here who knows CF? I mean, you always help people here, I guess next time I will use PM kiteless instead of posting topic

Reply With Quote
  #4  
Old January 27th, 2004, 09:29 AM
stpaz stpaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 17 stpaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 51 sec
Reputation Power: 0
instead of
<cfif Not IsDefined('form.choja')>
<cfset form.choja = "FIELD LEFT BLANK">
</cfif>

use

<cfparam name="form.choja" default="FIELD LEFT BLANK">

Reply With Quote
  #5  
Old January 27th, 2004, 09:32 AM
stpaz stpaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 17 stpaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 51 sec
Reputation Power: 0
you could add a hidden feild to the submitting page, call it CheckboxList. and use it after every single check box on the submiting page that way you can use the form.CheckboxList as a List an use cfloop to go through it.

Reply With Quote
  #6  
Old May 3rd, 2005, 04:24 PM
electric_head electric_head is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 1 electric_head User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 35 sec
Reputation Power: 0
Thumbs up Works, thanks!

Quote:
Originally Posted by stpaz
instead of
<cfif Not IsDefined('form.choja')>
<cfset form.choja = "FIELD LEFT BLANK">
</cfif>

use

<cfparam name="form.choja" default="FIELD LEFT BLANK">



I was having the same problem, but this really works, so I signed up to say thanks. You have no idea how long I've been searching for a solution to this.

Reply With Quote
  #7  
Old May 3rd, 2005, 09:43 PM
fx910 fx910 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Australia
Posts: 31 fx910 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 16 m 59 sec
Reputation Power: 6
Speedy way of doing many forms

To cover a whole bunch of form fields more quickly, don't forget you can also use a cfloop like this:
Code:
<cfloop list="liver,alergija,choja" index="Item">
    <cfparam name="form.#Item#" default="(Form left blank)" />
</cfloop>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > how to assign 'not defined' to all undefined form values??


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT