Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 09-30-2003, 07:03 PM   #1 (permalink)
Tilted
 
Email Form Results

I need to create a form that will send the results to both the enduser who filled out the form and the person who will be collecting the data. I've been trying to use a CGI script but know *nothing* about it, and haven't had much luck. Does anyone know of any *simple* (borderline idiotic) CGI scripts for this purpose? Or is there another way to do it that I'm overlooking? Any help would be hugely appreciated. Thanks in advance.
porndude is offline  
Old 10-01-2003, 07:48 AM   #2 (permalink)
Stop. Think. Question.
 
rubicon's Avatar
 
Location: Redondo Beach, CA
I have some code that might work for you. Are you looking for VBScript or PHP?
__________________
How you do anything is how you do everything.
rubicon is offline  
Old 10-01-2003, 02:36 PM   #3 (permalink)
Psycho
 
steveincolumbus's Avatar
 
Location: BFE, Kentucky
I am wanting the same thing so that i may to a form for wedding info on my website.... I am not able to use PHP so i guess a script would work for me... thanks
steveincolumbus is offline  
Old 10-02-2003, 02:51 PM   #4 (permalink)
Stop. Think. Question.
 
rubicon's Avatar
 
Location: Redondo Beach, CA
I have included sample VBScript. I pulled this from an existing page so it's out of context but it may work as is.

The VBScript checks to see if the form has already been submitted. If not, it presents the form with empty fields.

If it has been submitted, does it contain field validation errors? If so, display the field values and an error message.

When all errors are corrected the form is submitted via email. You can modify the code to create a text file on the server, add a database record, etc.

This is all server-side code and requires an IIS server (Windows 2000, 2003, XP) to run.

This code includes some string routines which are also included below.

PHP Code:
<!-- #include virtual="/includes/string_routines.asp" -->

<%

Dim strFieldMissing(10)

' see string_routins.asp include above
strErrorMsg = "<span class=formerror>&nbsp;&nbsp;<-- Required</span>"
strEmailErrorMsg = "<span class=formerror>&nbsp;&nbsp;<-- Doesn'
t match</span>"
strFirstName = makeAlpha(Request.Form("
firstname"))
strLastName = makeAlpha(Request.Form("
lastname"))
strTitle = makeAlpha(Request.Form("
title"))
strEmail1 = Request.Form("
email1")
strEmail2 = Request.Form("
email2")
strCompany = makeAlpha(Request.Form("
company"))
strStreet1 = makeAlpha(Request.Form("
street1"))
strStreet2 = makeAlpha(Request.Form("
street2"))
strCity = makeAlpha(Request.Form("
city"))
strState = makeAlpha(UCase(Request.Form("
state")))
strZip = Request.Form("
zip")
strTelephone = Request.Form("
telephone")
strReferrer = Request.Form("
referrer")
strComments = stringClean(Request.Form("
comments"))
strTOSAgree = Request.Form("
tos_agree")

for i = 0 to 10
    strFieldMissing (i) = false
next

if strFirstName = "" then strFieldMissing(0) = true
if strLastName = "" then strFieldMissing(1) = true
if not isEmail(strEmail1) then strFieldMissing(2) = true
if not isEmail(strEmail2) then strFieldMissing(3) = true
if strCompany = "" then strFieldMissing(4) = true
if strStreet1 = "" then strFieldMissing(5) = true
if strCity = "" then strFieldMissing(6) = true
if strState = "" or Len(strState) < 2 then strFieldMissing(7) = true
if not isZip(strZip) then strFieldMissing(8) = true
if not isPhone(strTelephone) then strFieldMissing(9) = true
if strTOSAgree <> "
true" then
    strFieldMissing(10) = true
    strTOSAgreeState = ""
else
    strTOSAgreeState = "
checked"
end if

if strEmail1 = strEmail2 then
    strEmailMatch = true
else
    strEmailMatch = false
end if

' do we have any erros?
strFormHasErrors = false
for i = 0 to 10
    if strFieldMissing (i) = true then strFormHasErrors = true
next

' have we run this before?
checkForSubmit = Request.Form("
wcp_submit")
if checkForSubmit <> "
Submit" then strFirstSubmit = true

' only display the form if this is the first time or we have errors to correct
if strFirstSubmit or strFormHasErrors then
%>

blah blah

<%
    if not strFirstSubmit and strFormHasErrors then Response.Write ("
<class=formerror align=center><B>Your Form Has Errors Please Correct and Submit Again</B></p>")
%>
    <form name="
wcp_app" method="POST" action="default.asp">
    <table align="
center">
        <tr>
            <td valign="
middle">First Name*</td>
            <td valign="
middle"><input name="firstname" type="text" size="30" maxlength="80" value="<%=strFirstName%>">
                <% if not strFirstSubmit and strFieldMissing(0) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr>
            <td valign="
middle">Last Name*</td>
            <td valign="
middle"><input name="lastname" type="text" size="30" maxlength="80" value="<%=strLastName%>">
                <% if not strFirstSubmit and strFieldMissing(1) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr>
            <td valign="
middle">Title</td>
            <td valign="
middle"><input name="title" type="text" size="30" maxlength="80" value="<%=strTitle%>">
            </td>
        </tr>
        <tr>
            <td valign="
middle">E-mail*</td>
            <td valign="
middle"><input name="email1" type="text" size="30" maxlength="80" value="<%=strEmail1%>">
                <%
                if not strFirstSubmit and not strEmailMatch then
                    Response.Write (strEmailErrorMsg)
                else
                    if not strFirstSubmit and strFieldMissing(2) then Response.Write (strErrorMsg)
                end if
                %>
            </td>
        </tr>
        <tr>
            <td valign="
middle">E-mail (confirm)*</td>
            <td valign="
middle"><input name="email2" type="text" size="30" maxlength="80" value="<%=strEmail2%>">
                <%
                if not strFirstSubmit and not strEmailMatch then
                    Response.Write (strEmailErrorMsg)
                else
                    if not strFirstSubmit and strFieldMissing(3) then Response.Write (strErrorMsg)
                end if
                %>
            </td>
        </tr>
        <tr> 
            <td valign="
middle">Company Name*</td>
            <td valign="
middle"><input name="company" type="text" size="30" maxlength="80" value="<%=strCompany%>">
                <% if not strFirstSubmit and strFieldMissing(4) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr>
            <td valign="
middle">Address 1*</td>
            <td valign="
middle"><input name="street1" type="text" size="30" maxlength="80" value="<%=strStreet1%>">
                <% if not strFirstSubmit and strFieldMissing(5) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr> 
            <td valign="
middle">Address 2</td>
            <td valign="
middle"><input name="street2" type="text" size="30" maxlength="80" value="<%=strStreet2%>"></td>
        </tr>
        <tr> 
            <td valign="
middle">City*</td>
            <td valign="
middle"><input name="city" type="text" size="30" maxlength="80" value="<%=strCity%>">
                <% if not strFirstSubmit and strFieldMissing(6) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr> 
            <td valign="
middle">State*</td>
            <td valign="
middle">
                <input name="
state" type="text" size="2" maxlength="2" value="<%=strState%>">
                <% if not strFirstSubmit and strFieldMissing(7) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr> 
            <td valign="
middle">ZIP*</td>
            <td valign="
middle"><input name="zip" type="text" size="10" maxlength="10" value="<%=strZip%>">
                <% if not strFirstSubmit and strFieldMissing(8) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr>
            <td valign="
middle">Telephone*</td>
            <td valign="
middle"><input name="telephone" type="text" size="12" maxlength="12" value="<%=strTelephone%>">
                <% if not strFirstSubmit and strFieldMissing(9) then Response.Write (strErrorMsg) end if %>
            </td>
        </tr>
        <tr>
            <td valign="
middle">How Did You Learn<br>About Us?</td>
            <td valign="
middle">
                <select name="
referrer">
                    <option value="
no answer" selected>-- Select from list --</option>
                    <option value="
Customer Referral">Customer Referral</option>
                    <option value="
E-mail">E-mail</option>
                    <option value="
Internet Advertising">Internet Advertising</option>
                    <option value="
Link from Another Web Site">Link from Another Web Site</option>
                    <option value="
On-Line Seminar">Attended On-Line Seminar</option>
                    <option value="
Printed Advertising">Printerd Advertising</option>
                    <option value="
Sales Call">Sales Call</option>
                    <option value="
Search Engine">Search Engine</option>
                    <option value="
Trade Journal">Trade Journal</option>
                    <option value="
Trade Show">Trade Show</option>
                    <option value="
Yellow Pages">Yellow Pages</option>
                    <option value="
Other">Other</option>
                </select>
            </td>
        </tr>
        <tr>
            <td valign="
middle">Comments</td>
            <td valign="
middle"><textarea name="comments" cols="30" rows="5"><%=strComments%></textarea></td>
        </tr>
        <tr>
            <td align="
center" colspan="2">
                <textarea readonly rows="
10" cols="50"><!-- #include virtual="/web_conferencing/tos.txt" --></textarea>
            </td>
        </tr>
        <tr>
            <td align="
center" colspan="2">
                <br>
                <input name="
tos_agree" type="checkbox" value="true" <%=strTOSAgreeState%>> I AGREE TO THESE TERMS OF SERVICE
                <% if not strFirstSubmit and strFieldMissing(10) then Response.Write (strErrorMsg) end if %>
                <br><br>
                <input type="
submit" name="wcp_submit" value="Submit">
            </td>
        </tr>
    </table>
    </form>
    <p><a name="
rates">*</a>Phone and web conference usage is billed at the prevailing rate; click <a href="/web_conferencing/web_conf.asp#plans">here</a> to review Plan and Rate information.</p>
<%
' we've submitted with no errorsso process the form data
else
%>
<%
    
Set Mailer Server.CreateObject ("SMTPsvg.Mailer")
    
    
Mailer.FromName "auto-mailer"
    
Mailer.FromAddress "p@l.com"
    
Mailer.RemoteHost "mail.verio.com"
    
Mailer.Subject "subject"
    
Mailer.AddRecipient "p@l.com""p@l.com"
    
strBodyText "Information" vbCrLf vbCrLf _
        
"Referrer: General Sign-Up Page" vbCrLf _
        
"Name: " strFirstName " " strLastName vbCrLf _
        
"Title: " strTitle vbCrLf _
        
"Company: " strCompany vbCrLf _
        
"Street1: " strStreet1 vbCrLf _
        
"Street2: " strStreet2 vbCrLf _
        
"City: " strCity vbCrLf _
        
"State: " strState vbCrLf _
        
"ZIP: " strZip vbCrLf _
        
"Telephone: " strTelephone vbCrLf _
        
"E-mail: " strEmail1 vbCrLf _
        
"Referral: " strReferrer vbCrLf _        
        
"Comments: " vbCrLf strComments vbCrLf _
        
"TOS Agreement: " strTOSAgreeState vbCrLf
    Mailer
.BodyText strBodyText

    On Error Resume Next
    returnCode 
Mailer.SendMail
    
if returnCode TRUE then
        Response
.Write "<p>Thank you.  Your account request has been sent and you will receive an e-mail confirmation when it has been processed.</p>"
    
else
        
strManualEmail "mailto:p@l.com?from=" strEmail "&subject=request" "&body=" strBodyText
        Response
.Write "<p>The system was unable to send your account request due to a mail send failure (Error: " Mailer.Response ").</p>"
%>
        <
p>Please <a href="/contact/">contact us</ato speak with a representative.</p>
<%
    
end if
    
Set Mailer=Nothing
end 
if
%> 
string_routines.asp

PHP Code:
<%

' REGULAR EXPRESSIONS  
Source: [url]http://www.aspalliance.com/chrisg/[/url]

Function makeAlpha(text)  
    
makeAlpha=regexReplace(text"[^A-Za-z0-9]","")  
End Function  
 
Function 
stringClean(text)  
    
stringClean=regexReplace(text"[^\w\d\s\@\_\-\.\n\r\/]","")  
End Function  
 
Function 
isEmail(email)  
    
isEmail=regexTest("[A-Za-z0-9\_\-]+\@[A-Za-z0-9\_\-]+.*\.\w{2,3}",email)  
End Function  

Function 
isZip(text)
    
isZip=regexTest("^\d{5}(-\d{4})?$",text)
End Function

Function 
isPhone(text)
    
isPhone=regexTest("^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$",text)
End Function

Function 
regexReplace(sourceexpressionreplaceWith)  
    
dim regEx ' Create variables.  
    Set regEx = New RegExp ' 
Create regular expression.  
    
regEx.Pattern expression ' Set pattern.  
    regEx.IgnoreCase = True ' 
Make case insensitive.  
    
regEx.Global = True ' Make global  
    regexReplace = regEx.Replace(source, replaceWith) ' 
Make replacement.  
End Function  
 
Function 
regexTest(expressiontext)  
    
dim regExMatchMatches ' Create variable.  
    Set regEx = New RegExp ' 
Create a regular expression.  
    
regEx.Pattern expression ' Set pattern.  
    regEx.IgnoreCase = True ' 
Set case insensitivity.  
    
regEx.Global = True ' Set global applicability.  
    regexTest = regEx.test(text) ' 
Execute search.  
End Function  
 
Function 
regexMatch(expressiontext)
    
dim regExMatchMatches ' Create variable.  
    Set regEx = New RegExp ' 
Create a regular expression.  
    
regEx.Pattern expression ' Set pattern.  
    regEx.IgnoreCase = True ' 
Set case insensitivity.  
    
regEx.Global = True ' Set global applicability.  
    Set Matches = regEx.Execute(text) ' 
Execute search.  
    for 
each Match in Matches ' Iterate Matches collection.  
        RetStr = RetStr & Match.Value & ","  
    next  
    regexMatch = RetStr  
End Function  

%> 
__________________
How you do anything is how you do everything.
rubicon is offline  
 

Tags
email, form, results

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 05:20 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360