• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Form info sent to both an email and a database

New Here ,
Jan 14, 2013 Jan 14, 2013

Copy link to clipboard

Copied

Someone know a good code that will allow a web base form be sent to an email and also a database?

Views

461

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 14, 2013 Jan 14, 2013

Copy link to clipboard

Copied

It's a simple matter to code.  Use both CFMAIL and CFQUERY on the same processing page.

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2013 Jan 14, 2013

Copy link to clipboard

Copied

Hi Wolfshade, thankyou for looking at my question, as my name indicates I am not a great coder so if you could post a sample of using both on the processing page I would really appreciate it

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 14, 2013 Jan 14, 2013

Copy link to clipboard

Copied

If you want it sent to a static email address:

<cfmail to="sendtouser@domain.com" subject="Email Form Data">

  #form.field1#

  #form.field2#

  ...

  #form.fieldn#

</cfmail>

<cfquery name="insertData" datasource="#yourDSN#">

  INSERT into tableA(columnA, columnB, columnC, columnD)

  VALUES(<cfqueryparam value="#form.field1#" cfsqltype="CFSQLVARCHAR">,<cfqueryparam value="#form.field2#" cfsqltype="CFSQLVARCHAR">,

               <cfqueryparam value="#form.field3#" cfsqltype="CFSQLDATETIME">,<cfqueryparam value="#form.field4#" cfsqltype="CFSQLINTEGER">)

</cfquery>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 14, 2013 Jan 14, 2013

Copy link to clipboard

Copied

LATEST

The problem is that most of the code is variable depending on what you are collecting and what you want to save.

Here is a brief run through:

To send email I recommend you first configure the email server in CF Admin.  Then use the following code:

<cfmail to="recipentsAddress@none.com" from="fromAddress@none.com" subject="Form Variables" type="text/html">

<cfdump var="#form#" format="html">

</cfmail>

Here is more info on using the cfmail tag:  http://livedocs.adobe.com/coldfusion/8/Tags_m-o_01.html

Next, saving the data to a table.

<cfquery name="qSaveform" datasource="YourDatasource">

Insert INTO YourTable (columnlist) values (form variables);

</cfquery>

More info on cfquery:  http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_17.html

Please also read about the cfqueryparam to protect yoruself from SQL injections:  http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_18.html

After writting all of this I'm not sure how helpful it is.  There is so much more to it that its hard to direct you.  Use what I've posted here and get a feel for the two tags.  As you run into problems ask more questions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation