December 11th, 2003, 09:41 AM
Forms and mailing
Does anyone know how to create a check box that defines whether or not a mail message gets sent. i cant seem to get the cfif statements to work.
heres what i have so far:
<cfif contactdirector equal "on">got here
<cfelseif contactdirector is "off">got here2
Whenever the checkbox on the form is not checked, the parameter doesnt seem to be sent at all. when it is checked it works.
December 12th, 2003, 02:51 PM
That's because when a form checkbox is not checked, there IS NO VARIABLE AT ALL for that field. So what you want it:
<cfif isDefined( 'form.contactDirector' )>
-- code that fires when the box is checked
-- code that fires when the box is not checked
December 15th, 2003, 12:17 PM
Darn checkbox gets ya all the time... I spent a week tracking this one down in another app ... I knew the issue, just forgot cuz it's intuitive to expect it to be there. You're not alone, infinity...
March 10th, 2004, 02:19 AM
more problems with forms and checkboxes
I am having the same type of problem as infinity2003.
Here is the relevant code that I have in the HTML file:
And here is what I have in the cfmail.cfm file:
<form name="jobForm" action="cfmail.cfm" method="post">
<input type="checkbox" name="postJob" id="postJob" value="on" />
<label for="postJob">Post job on our website.</label><br />
<input type="checkbox" name="sendResumes" id="sendResumes" value="on" />
<label for="sendResumes">E-mail resumes from our existing database with memo.</label><br />
<input type="checkbox" name="addToMailingList" id="addToMailingList" value="on" />
<label for="addToMailingList">Add me to the career fair mailing list.</label><br />
<input type="checkbox" name="isInquiry" id="isInquiry" value="on" />
<label for="isInquiry">Do not advertise job (inquiry only).</label><br />
There are other items that are on the form (textboxes, select boxes, etc.) that I am able to post from the html file and mail from the cfmail.cfm. The only time that the script executes without an error is if I check all of the checkboxes and then submit the form. If at least one is unchecked, then the ColdFusion error comes up saying that form.[oneofthecheckboxes] cannot be found. Does anyone know how I can fix this? Thank you in advance, sorry if some of this does not make sense, it is late and I am quite tired..
<cfmail to = "#form.mailTo#" from = "noReply@domain.com" subject = "Automated Job Submission">
<cfif IsDefined("form.postJob")>Post job on our website.</cfif>
<cfif IsDefined("form.sendResumes")>E-mail resumes from our existing database with memo.</cfif>
<cfif IsDefined("form.addToMailingList")>Add me to the career fair mailing list.</cfif>
<cfif IsDefined("form.isInquiry")>Do not advertise job (inquiry only).</cfif>
March 10th, 2004, 08:31 PM
Seems like there must be some other code, because I don't see anything in the code you posted that would throw an error, even if you did not check a form box. Can you post the actual error text and/or post any extra code in the cfmail.cfm page that you did not already post?
March 10th, 2004, 09:26 PM
You are absolutely correct. I was getting an error when I was using #form.checkboxname#. Everything started to work after I replaced these with "form.checkboxname". Thanks for the reply.