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?
Copy link to clipboard
Copied
It's a simple matter to code. Use both CFMAIL and CFQUERY on the same processing page.
^_^
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
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>
Copy link to clipboard
Copied
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.