#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    100
    Rep Power
    11

    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:

    <cfoutput>
    <cfif contactdirector equal "on">got here
    <cfelseif contactdirector is "off">got here2
    </cfif>
    </cfoutput>

    Whenever the checkbox on the form is not checked, the parameter doesnt seem to be sent at all. when it is checked it works.

    thanks
    greg
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,275
    Rep Power
    968
    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
    <cfelse>
    -- code that fires when the box is not checked
    </cfif>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    32
    Rep Power
    11
    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...
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    2
    Rep Power
    0

    Unhappy 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:

    Code:
    <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 />
    </form>
    And here is what I have in the cfmail.cfm file:

    Code:
    <cfmail to = "#form.mailTo#" from = "noReply@domain.com" subject = "Automated Job Submission">
    OPTIONS:
    <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>
    </cfmail>
    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..
  8. #5
  9. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,275
    Rep Power
    968
    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?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    2
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo