<%
// ============================================
The content of this page
// ============================================
function Content ()
{
Out (' <td width= ' 20% ' > </td> ');
Out (' <td width= "60%" > ");
If the form has a password, validate it
So, if it fails we can show the form again
var bsubmitted = (Request.Form.Count > 0);
Has the form been submitted?
if (bsubmitted)
{
Get the password from the form ...
Spassword = "" + Request.Form ("password");
Validate the password and moan if it fails
if (Spassword!= sDBPath)
{
Out (' Pretend the form hasn ' t been sent yet
bsubmitted = false;
}
}
Show the form if not submitted yet
if (!bsubmitted)
{
Out (' in <a href= "subscribe.asp" >part 1</a> I showed you I allowed your to Subscribe to my mailing list. H Ere\ ' s where I can post an email to the members of that mailing list.
Out (' <p>strangely, I\ ' m don't going to let your do it, but your <i>can</i> get the source code from the Bo Ttom of the page, and learn how I did it. ');
Here ' s the form tag. The action attribute is the name of
The file that'll be called with the answer-in this case
It ' s the same page. The method can is "post" to send the
form data ' behind the scenes ' or ' get ' to appending the
Data to the URL in the style page.asp?data1=a&data2=b
//
Use post most of the time-it ' neater and ' get ' is limited
In the amount of data this can be sent.
Out (' <form action= "mailtolist.asp" method= "post" > ");
Another table to line up the titles and inputs
Out (' <table border= "0" cellpadding= "0" > ");
Out (' <tr><td align= ' right ' valign= ' top ' > ');
Out (' Password: ');
Out (' </td><td align=, left ' valign= ' top ' > ');
A simple text box. We ' ll reference it with the name ' password '
and show Notoginseng characters on the form. Use the MaxLength
attribute to set the maximum characters they can enter.
Use value= ' some text ' to pre-fill the ' input with data.
Out (' <input type= "password" name= "password" size= "></input>");
Out (' </td></tr> ');
Out (' <tr><td align= ' right ' valign= ' top ' > ');
Out (' message: ');
Out (' </td><td align=, left ' valign= ' top ' > ');
TextArea is a multiline text box. Specify the size with the
cols and rows attributes. Wrap can be ' off ' (the default)
"Physical" or "virtual". As an example, consider the user
Typing in the following text in a character wide input:
//
"I wonder how this text would appear to the" Server I send it? "
//
Wrap= "Off" would send it as typed, but the user has to scroll off
To the right to the text. (horrid)
//
wrap= "Physical" would physically split the line after the word
' Server ' and send two lines to the server
//
wrap= "virtual" would send one line, as typed, but the user
Would the text nicely wrap in the input. perfect!
Out (' <textarea name= "message" cols= "rows=" 8 "wrap=" Physical "></textarea>");
Out (' </td></tr> ');
Out (' <tr><td align= ' right ' valign= ' top ' > ');
Out (");
Out (' </td><td align=, left ' valign= ' top ' > ');
Type= ' Submit ' provides a submit button to perform the
Form action. The button says "Submit" unless you override
With the value attribute.
Out (' <input type= "submit" value= "Send Mail" ></input> ");
Out (' </td></tr> ');
Out (' </table> ');
Out (' </form> ');
}
Else
{
Get the message from the form
var smessage = "" + Request.Form ("message");
Open the connection
Dbinitconnection ();
Get the emails addresses
var sSQL = ' SELECT Email from mailinglist; ';
Dbgetrecords (sSQL);
var semaillist = "";
var sSep = "";
while (!orecordset.eof)
{
Semaillist + + SSep + orecordset (0);
SSep = ";";
Orecordset.movenext ();
}
Free the connection
Dbreleaseconnection ();
Email (' it\ ' a shawthing-what\ ' s new?, Semaillist, smessage);
Out (' <p>email sent successfully.<p> ');
}
Out (' Want to-to-you-the-this form to mail the subscribers is done? Click below to get all the source code! ');
Out (' <p><center><a href= "showsource.asp? page=mailtolist" ></a></center>");
Out (' </td> ');
Out (' <td width= ' 20% ' > </td> ');
}
// ============================================
Email me!
// ============================================
function Email (Ssubject, Semail, smessage)
{
Send an email to the address just to confirm what just happened
var omail = Server.CreateObject ("CDONTS.") NewMail ");
Setup The Mail
Omail.from = omail.to = ' MailingList@shawthing.com ';
OMAIL.BCC = Semail;
Omail.importance = 1;
Omail.subject = Ssubject;
Omail.body = smessage;
Send it
Omail.send ();
Release Object
Omail = null;
}
%>
Utils/database.asp
<%
Globals
var oconnection;
var Orecordset;
var sconnection;
// ============================================
Example usage:
Dbinitconnection ();
//
var sSQL = "Select * from somewhere";
//
Dbgetrecords (sSQL);
//
... use Orecordset
//
Dbreleaserecords (); Optional step
//
Dbreleaseconnection ();
// ============================================
// ============================================
Initializes database variables for the on page
// ============================================
function Dbinitconnection ()
{
Don ' t open it again if already opened!
if (sconnection!= undefined)
Return
Get Connection Object
oconnection = Server.CreateObject (' ADODB. Connection ');
Get the database connection string
Use MapPath to make relative path into physical path
Sconnection = ' provider=microsoft.jet.oledb.4.0; Data source= ' + server.mappath (sDBPath);
Open the connection
Oconnection.open (sconnection);
As a attempt at optimization we open
The recordset here, not in Dbgetrecords ()
Orecordset = Server.CreateObject (' ADODB. Recordset ');
}
// ============================================
Tidies up after Dbinitconnection
// ============================================
function Dbreleaseconnection ()
{
Don ' t release the connection if not connected!
if (sconnection = = undefined)
Return
As a attempt at optimization we-close
The recordset here, not in Dbreleaserecords ()
if (orecordset.state!= 0)
Orecordset.close ();
Orecordset = undefined;
Oconnection.close ();
oconnection = undefined;
sconnection = undefined;
}
// ============================================
Executes the passed in SQL statement
and returns the Orecordset object
// ============================================
function Dbgetrecords (sSQL)
{
Remember this can fail if passed garbage, and hence
' Orecordset ' would already be ' closed '
Orecordset = Oconnection.execute (sSQL);
}
// ============================================
Tidies up after Dbgetrecords
// ============================================
function Dbreleaserecords ()
{
Important:this FUNCTION intentionally BLANK
As an attempt in optimization we now open/close
The recordset with the connection and not separately
So all code is moved to Dbreleaseconnection.
It is recommended which you still call this function as soon
As the recordset is finished with.
Note that it's assumed by the caller, it is legal
To call Dbreleaseconnection without calling the This function
}
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.