9 Replies Latest reply on Apr 11, 2008 9:57 AM by

    3-Function Action Page

    newportri Level 1
      Greetings
      I am having an issue with a form submission action page- I can get it to send the field contents to an email, and capture in a DB with the same action page- but when an file is chosen to upload, it fails.

      I need to have cfinsert, cfmail to, and cffile action = "upload" on the same action page. The submitter may or may not upload a file with the submission, so I tried <cfif isDefined("Form.FileContents") > upload the file</cfif>, then insert in DB, then send the email.

      Any help would be appreciated- Thanks

      newportri
        • 1. Re: 3-Function Action Page
          Dan Bracuk Level 5
          cfdump is your freind.

          submit your form without uploading a file. then do this

          <cfdump var="#isDefined('Form.FileContents') "#>
          <cfdump var="#Form.#">
          <cfabort>
          • 2. Re: 3-Function Action Page
            newportri Level 1
            Thanks for your quick response- It may be easier to show the code on the action page, then you can suggest a fix because I don't know why I'd dump the variables?

            The Submitter is not required to upload a file with their submission (They may or may not).

            ACTION PAGE:

            <cfif isDefined("Form.FileContents") >
            <cffile action = "upload"
            filefield = "FileContents"
            destination = "c:\Inetpub\wwwroot\whatever\"
            accept = "image/jpg,image/jpeg,image/pjpeg,image/gif,text/anytext,application/octet-stream"
            nameConflict = "MakeUnique"> </cfif>



            <cfinsert datasource="whatever" tablename="whatever">


            <cfmail to="whatever@whatever.com"
            from="#Form.request_email#"
            subject="whatever"
            server ="whatever">


            The following is the result of a Form Submission:

            Date: #dte_received#
            Time: #tme_received#

            ETC.
            </cfmail>

            <html>
            <head>
            <title> Form Submission</title>
            </head

            <body>
            <h3>Thank You For Your Submission</h3>
            </body>
            </html>

            Thanks...

            newportri
            • 3. Re: 3-Function Action Page
              Dan Bracuk Level 5
              Dumping variables is a debugging technique. Once you have solved the problem, you take out the dump tags.
              • 4. Re: 3-Function Action Page

                How's your FORM written? Did you have the enctype="multipart/form-data" Attribute?

                • 5. Re: 3-Function Action Page
                  newportri Level 1
                  Yes:

                  <form action="request_support_action.cfm" method="post" enctype="multipart/form-data">


                  Thanks-

                  newportri
                  • 6. Re: 3-Function Action Page
                    Probably you've already tried changing the order of processing:
                    a) data capture;
                    b) file manipulation;
                    c) email
                    • 7. Re: 3-Function Action Page
                      newportri Level 1
                      Greetings

                      Thanks- When the data capture is first, it looks for the form input name ,

                      ERROR=

                      "The FILECONTENTS fieldname cannot be found in the main table."

                      This is not a named field in the DB- I'm simply storing the file in a directory.

                      When the file manipulation is first with no file attached with the submitted form,

                      ERROR=

                      The form field FileContents did not contain a file.


                      Thanks again

                      newportri
                      • 8. Re: 3-Function Action Page
                        newportri Level 1
                        Thanks to all who responded - I found the solution-

                        Sequence-

                        1) Data capture

                        2) Mail to

                        3) <cfif #Form.FileContents# IS "">
                        <cfabort>
                        <cfelse>
                        <cffile action = "upload"
                        filefield = "FileContents"
                        destination = "c:\whatever"
                        accept = "image/jpg,image/jpeg,image/pjpeg,image/gif,text/anytext,application/octet-stream"
                        nameConflict = "MakeUnique"> </cfif>


                        Thanks!
                        • 9. Re: 3-Function Action Page
                          Actaully they shouldn't make any difference, but the sequence I wrote is my preference. Also, make sure to use cftry and cfcatch for each process ...