|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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:
Thanks! |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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 ![]() |
|
#4
|
|||
|
|||
|
instead of
<cfif Not IsDefined('form.choja')> <cfset form.choja = "FIELD LEFT BLANK"> </cfif> use <cfparam name="form.choja" default="FIELD LEFT BLANK"> |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
Quote:
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. |
|
#7
|
|||
|
|||
|
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>
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > how to assign 'not defined' to all undefined form values?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|