Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables back and forth for error checking

Status
Not open for further replies.

brimike

MIS
Feb 14, 2006
26
US
Hello,
I am having a problem passing avriables that are already in the form to the handler. Once I submit I lose the entire query string and the fields that were populated with user input are also lost. I was able to pass data to the form however when you submit the form leaving a field empty the error comes out fine but the string is gone as well as any user data that was entered.



The Form--------------
<%@ Language=VBScript %>

<%
Option Explicit
%>
<%

dim strErrText, strAction, varMessage, varAssociate, varAgentEmail, varMessage2, varMessage3, AgentEmail, varMLS, strName


'--------------
strAction = Request.QueryString("action")
AgentEmail = Request.QueryString("AgentEmail")
Select Case strAction

Case "err1"
strErrText = "<span style='font-family: Verdana; font-size: 11px;color: red; font-weight: bold;'>Error: Please enter your First Name.</span>"
Case "err2"
strErrText = strErrText & "<span style='font-family: Verdana; font-size: 11px;color: red; font-weight: bold;'>Error: Please enter your Last Name.</span>"
Case "err3"
strErrText = strErrText & "<span style='font-family: Verdana; font-size: 11px;color: red; font-weight: bold;'>Error: Please enter your e-mail address.</span>"
Case "err4"
strErrText = strErrText & "<span style='font-family: Verdana; font-size: 11px;color: red; font-weight: bold;'>Error: Please enter your Zip Code.</span>"
Case "err5"
strErrText = strErrText & "<span style='font-family: Verdana; font-size: 11px;color: red; font-weight: bold;'>Error: Please enter your City.</span>"

End Select
%>

<%
if strAction > "" then
response.write strErrText
end if
%>
<%
varMLS = request("mls")
If varMLS <> "" Then
varMessage ="Please send more information on property " & varMLS
End If
%>
<%
varAssociate = request("Associate")
If varAssociate <> "" Then
varMessage2 ="" & varAssociate
End If
%>


<%
AgentEmail = request("AgentEmail")
If AgentEmail <> "" Then
varMessage2 ="" & AgentEmail
End If
%>


</td>
</tr>
<tr>
<td height="743" valign="top">
<form name="form1" method="post" action="send_it_test1.asp">

<div align="right"> <strong><font color="#CC0000" size="4">
</font></strong><font color="#990000" size="2" face="Arial, Helvetica, sans-serif"><strong></strong></font>
<table width="106%" border="0" cellspacing="3" cellpadding="2">
<tr class="devTXT">
<td width="13%"><div align="right" class="smclientfont">First
Name: </div></td>
<td width="37%" colspan="2"> <div align="left">
<input name="firstname" type="text" class="formfield" value="<% =strName %>">

<font color="#CC0000" size="4"><strong>*</strong></font></div></td>
<td width="12%"><div class="frontface">
<div align="right" class="smclientfont">Last
Name:</div>
</div></td>
<td width="38%"> <div align="left">
<input name="lastname" type="text" class="formfield" value="">
<font color="#CC0000" size="4"><strong>*</strong></font></div></td>
</tr>
<tr class="devTXT">
<td><div align="right">Company:</div></td>
<td colspan="2"><input name="company" type="text" class="formfield" value=""></td>
<td><div align="right">eMail:</div></td>
<td><input name="email" type="text" class="formfield" value="">
<font color="#CC0000" size="4"><strong>*</strong></font></td>
</tr>
<tr class="devTXT">
<td><div align="right" class="smclientfont">Position:</div></td>
<td colspan="2"> <div align="left">
<input name="position" type="text" class="formfield" value="">
</div></td>
<td><div class="frontface">
<div align="right" class="smclientfont">State<font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial">:</font></font></font></div>
</div></td>
<td align="left"> <div align="left"> <font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial">
<input name="state" type="text" class="formfield" value="">
</font></font></font></span></font><font color="#CC0000" size="4"></font></div></td>
</tr>
<tr class="devTXT">
<td><div align="right">Street:</div></td>
<td colspan="2"><input name="street" type="text" class="formfield" value=""></td>
<td><div align="right"><span class="smclientfont">Zip:</span></div></td>
<td><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial">
<input name="zip" type="text" class="formfield" value="" size="8" maxlength="8">
</font></font></font></span></font></font></font></span></font></font></font></span></font></font></font></span></font><span style="font-size: large"><font face="arial"> <font face="arial"><font color="#CC0000"><strong>*</strong></font></font></font></span></td>
</tr>
<tr class="devTXT">
<td><div class="smclientfont">
<div align="right">City:</div>
</div></td>
<td colspan="2"><input name="city" type="text" class="formfield" value="">
<font color="#CC0000" size="4"><strong>*</strong></font> </td>
<td><div align="right" class="smclientfont"><font size="-1" face="arial"></font></div></td>
<td align="left"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial">
</font></font></font></span></font></font></font></span></font></font></font></span></font></td>
</tr>
<tr class="devTXT">
<td><div class="frontface">
<div align="right" class="smclientfont">Country:</div>
</div></td>
<td colspan="2"> <div align="left"> <span class="frontface"><font size="-1" face="arial"><span class="frontface"></span>
<input type=hidden name="country" value="">
<select name="country" class="devTXT">
<option value="United States / Canada"selected>United
States / Canada</option>
<option value="Afgha">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Antarctica">Antarctica / Norfolk
Island</option>
<option value="Antigua">Antigua and Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Ascension">Ascension Island</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bosnia">Bosnia &amp; Herzogovina</option>
<option value="Botswana">Botswana</option>
<option value="Brazil">Brazil</option>
<option value="Brunei">Brunei</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Cape Verde Islands">Cape Verde
Islands</option>
<option value="236">Central African Republic</option>
<option value="235">Chad</option>
<option value="56">Chile</option>
<option value="86">China (PRC)</option>
<option value="57">Colombia</option>
<option value="269">Comoros / Mayotte Island</option>
<option value="242">Congo</option>
<option value="243">Congo, Dem. Rep. of (former
Zaire)</option>
<option value="Cook">Cook Islands</option>
<option value="506">Costa Rica</option>
<option value="385">Croatia</option>
<option value="53">Cuba</option>
<option value="357">Cyprus</option>
<option value="420">Czech Republic</option>
<option value="45">Denmark</option>
<option value="246">Diego Garcia</option>
<option value="253">Djibouti</option>
<option value="670">East Timor</option>
<option value="593">Ecuador</option>
<option value="20">Egypt</option>
<option value="503">El Salvador</option>
<option value="240">Equatorial Guinea</option>
<option value="291">Eritrea</option>
<option value="372">Estonia</option>
<option value="251">Ethiopia</option>
<option value="298">Faeroe Islands</option>
<option value="500">Falkland Islands</option>
<option value="679">Fiji Islands</option>
<option value="358">Finland</option>
<option value="33">France</option>
<option value="594">French Guiana</option>
<option value="689">French Polynesia</option>
<option value="241">Gabon</option>
<option value="220">Gambia</option>
<option value="995">Georgia</option>
<option value="49">Germany</option>
<option value="233">Ghana</option>
<option value="350">Gibraltar</option>
<option value="30">Greece</option>
<option value="299">Greenland</option>
<option value="590">Guadeloupe</option>
<option value="502">Guatemala</option>
<option value="224">Guinea (PRP)</option>
<option value="245">Guinea-Bissau</option>
<option value="592">Guyana</option>
<option value="509">Haiti</option>
<option value="504">Honduras</option>
<option value="852">Hong Kong</option>
<option value="36">Hungary</option>
<option value="354">Iceland</option>
<option value="91">India</option>
<option value="62">Indonesia</option>
<option value="98">Iran</option>
<option value="964">Iraq</option>
<option value="353">Ireland</option>
<option value="972">Israel</option>
<option value="39">Italy</option>
<option value="225">Ivory Coast (C&ocirc;te
d`Ivoire)</option>
<option value="81">Japan</option>
<option value="962">Jordan</option>
<option value="254">Kenya</option>
<option value="686">Kiribati</option>
<option value="850">Korea (North)</option>
<option value="82">Korea (South)</option>
<option value="965">Kuwait</option>
<option value="996">Kyrgyz Republic</option>
<option value="856">Laos</option>
<option value="371">Latvia</option>
<option value="961">Lebanon</option>
<option value="266">Lesotho</option>
<option value="231">Liberia</option>
<option value="218">Libya</option>
<option value="423">Liechtenstein</option>
<option value="370">Lithuania</option>
<option value="352">Luxembourg</option>
<option value="853">Macau</option>
<option value="389">Macedonia</option>
<option value="261">Madagascar</option>
<option value="265">Malawi</option>
<option value="60">Malaysia</option>
<option value="960">Maldives</option>
<option value="223">Mali Republic</option>
<option value="356">Malta</option>
<option value="692">Marshall Islands</option>
<option value="596">Martinique / French Antilles</option>
<option value="222">Mauritania</option>
<option value="230">Mauritius</option>
<option value="52">Mexico</option>
<option value="691">Micronesia (Federal States
of)</option>
<option value="808">Midway Island / Wake Island</option>
<option value="373">Moldova</option>
<option value="377">Monaco</option>
<option value="976">Mongolia</option>
<option value="212">Morocco</option>
<option value="258">Mozambique</option>
<option value="95">Myanmar</option>
<option value="264">Namibia</option>
<option value="674">Nauru</option>
<option value="977">Nepal</option>
<option value="31">Netherlands</option>
<option value="599">Netherlands Antilles /
Cura&ccedil;ao</option>
<option value="687">New Caledonia</option>
<option value="64">New Zealand</option>
<option value="505">Nicaragua</option>
<option value="227">Niger</option>
<option value="234">Nigeria</option>
<option value="683">Niue</option>
<option value="47">Norway</option>
<option value="968">Oman</option>
<option value="92">Pakistan</option>
<option value="680">Palau</option>
<option value="970">Palestine</option>
<option value="507">Panama</option>
<option value="675">Papua New Guinea</option>
<option value="595">Paraguay</option>
<option value="51">Peru</option>
<option value="63">Philippines</option>
<option value="48">Poland</option>
<option value="351">Portugal</option>
<option value="974">Qatar</option>
<option value="262">R&eacute;union Island</option>
<option value="40">Romania</option>
<option value="7">Russian Federation</option>
<option value="250">Rwanda</option>
<option value="869">Saint Kitts and Nevis</option>
<option value="378">San Marino</option>
<option value="239">S&atilde;o Tom&eacute; and
Principe</option>
<option value="966">Saudi Arabia</option>
<option value="221">Senegal</option>
<option value="248">Seychelles Islands</option>
<option value="232">Sierra Leone</option>
<option value="65">Singapore</option>
<option value="421">Slovak Republic</option>
<option value="386">Slovenia</option>
<option value="677">Solomon Islands</option>
<option value="252">Somalia</option>
<option value="27">South Africa</option>
<option value="34">Spain</option>
<option value="94">Sri Lanka</option>
<option value="290">St. Helena</option>
<option value="508">St. Pierre / Miquelon</option>
<option value="249">Sudan</option>
<option value="597">Suriname</option>
<option value="268">Swaziland</option>
<option value="46">Sweden</option>
<option value="41">Switzerland</option>
<option value="963">Syria</option>
<option value="886">Taiwan</option>
<option value="992">Tajikistan</option>
<option value="255">Tanzania</option>
<option value="66">Thailand</option>
<option value="228">Togo</option>
<option value="690">Tokelau</option>
<option value="676">Tonga Islands</option>
<option value="216">Tunisia</option>
<option value="90">Turkey</option>
<option value="993">Turkmenistan</option>
<option value="688">Tuvalu</option>
<option value="256">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="971">United Arab Emirates</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States / Canada">United
States / Canada</option>
<option value="0">Unknown</option>
<option value="598">Uruguay</option>
<option value="998">Uzbekistan</option>
<option value="678">Vanuatu</option>
<option value="58">Venezuela</option>
<option value="84">Vietnam</option>
<option value="681">Wallis and Futuna Islands</option>
<option value="685">Western Samoa</option>
<option value="967">Yemen</option>
<option value="381">Yugoslavia</option>
<option value="260">Zambia</option>
<option value="263">Zimbabwe</option>
</select>
</font></span></div></td>
<td><div align="center"></div></td>
<td><div align="left"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial"><span class="frontface"><font size="-1" face="arial"><font size="-1" face="arial"><font size="-1" face="arial">
</font></font></font></span> </font></font></font></span>
</font></div></td>
</tr>
<tr class="devTXT">
<td><div align="right" class="smclientfont">Phone:</div></td>
<td colspan="2">(
<input name="areacode" type="text" class="formfield" value="" size="3" maxlength="3">
)
<input name="phone" type="text" class="formfield" value="" size="7" maxlength="7">
<font face="arial">&nbsp; </font> </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td colspan="2"><strong>I am interested in the following:</strong></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td><div align="right" class="smclientfont"></div></td>
<td>Purchasing a Residence: </td>
<td><input name="purchase" type="radio" value="yes" checked>
Yes
<input type="radio" name="purchase" value="no">
No </td>
<td> <font face="arial">&nbsp;</font></td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td>Listing a Property:</td>
<td><input name="list" type="radio" value="yes" checked>
Yes
<input type="radio" name="list" value="no">
No </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td>Rental information:</td>
<td><input name="rental" type="radio" value="yes" checked>
Yes
<input type="radio" name="rental" value="no">
No</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td>Commercial Property:</td>
<td><input name="commercial" type="radio" value="yes" checked>
Yes
<input type="radio" name="commercial" value="no">
No</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td>Our Property Magazine:</td>
<td><input name="mag" type="radio" value="yes" checked>
Yes
<input type="radio" name="mag" value="no">
No</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td>Our E-newsletter.</td>
<td><input name="newsletter" type="radio" value="yes" checked>
Yes
<input type="radio" name="newsletter" value="no">
No</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td>Timeframe:</td>
<td><select name="timeframe" class="devTXT" id="timeframe">
<option>3 - 6 months</option>
<option>6 -12 months</option>
<option>1 - 2 Years</option>
</select></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td>Property Type:</td>
<td><select name="proptype" class="devTXT" id="proptype">
<option>Single Family
<option>Condominium
<option>Investment
</select></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>


<tr class="devTXT">
<td>&nbsp;</td>
<td>MLS Number : </td>
<td><%=varMLS%>
<input name="AgentName" type="hidden" id="AN" value="<%=varAssociate%>">
<input name="AgentEmail" type="hidden" id="Aemail" value="<%=AgentEmail%>">
<input name="varMLS" type="hidden" id="mls" value="<%=varMLS%>"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr class="devTXT">
<td><div align="right"></div></td>
<td colspan="2"><label><%=AgentEmail%></label></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td><div align="right">Questions?</div></td>
<td colspan="2">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td colspan="2" align="left"> <div align="left">
<textarea name="message" cols="30" rows="6" class="formfield"><%=varMessage%>

</textarea>
</div></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="devTXT">
<td>&nbsp;</td>
<td colspan="2">
<input name="submit" type="submit" class="SearchButtons" style="background-color:#000000 ;font-size: 9pt; color: white; font-weight:bold" value="Submit"></td>
<td>&nbsp;</td>
------------------------------------------------

The handler---------------------------
<%@ Language=VBScript %>

<%
Option Explicit
%>
<%
' -----------------------------------------------------
' CDONTS Email send script
' © ' Comments must remain intact for re-use of this code
' -----------------------------------------------------


dim strName, strLName, strCompany, strPosition, strStreet, strCity, strEmail, strState, strZip, optCountry, strArea, strPhone, strMessage, strProp, strList, strRental, strCommercial, strMag, strNewsletter, optTimeframe, optProptype, AgentEmail, AgentName, varMLS, city, zip

strName = Request.Form("firstname") ' holds inputted name
strLName = Request.Form("lastname") ' holds inputted name
strCompany = Request.Form("company") ' holds inputted name
strPosition = Request.Form("position") ' holds inputted name
strStreet = Request.Form("street") ' holds inputted name
strCity = Request.Form("city") ' holds inputted name
strState = Request.Form("state") ' holds inputted name
strZip = Request.Form("zip") ' holds inputted name
optCountry = Request.Form("country").Item ' drop down list selection
strArea = Request.Form("areacode") ' holds inputted name
strPhone = Request.Form("phone") ' holds inputted name
strEmail = Request.Form("email") ' holds inputted email address
strProp = Request.Form("purchase") ' holds inputted message
strList = Request.Form("list") ' holds inputted message
strRental = Request.Form("rental") ' holds inputted message
strCommercial = Request.Form("commercial") ' holds inputted message
strMag = Request.Form("mag") ' holds inputted message
strNewsletter = Request.Form("newsletter") ' holds inputted message
optTimeframe = Request.Form("timeframe").Item ' drop down list selection
optProptype = Request.Form("proptype").Item ' drop down list selection
AgentEmail = Request.Form("AgentEmail") ' holds inputted messageAgentEmail
AgentName = Request.Form("AgentName") ' holds inputted messageAgentName
varMLS = Request.Form("varMLS") ' holds mls
strMessage = Request.Form("message") ' holds inputted message

'-----Check email Validity----------
' -- check all fields for empty values --
' -- remove and add new as required --



if strName = "" then
Response.Redirect "contactus1.asp?action=err1"
else if strLname = "" then
Response.Redirect "contactus1.asp?action=err2&varMLS=""varMLS"
else if strEmail = "" then
Response.Redirect "contactus1.asp?action=err3"
else if zip = "" then
Response.Redirect "contactus1.asp?action=err4"
else if city = "" then
Response.Redirect "contactus1.asp?action=err5"
end if
end if
end if
end if
end if
' -- begin email send process --

dim objMail

Set objMail = CreateObject("CDONTS.NewMail")

' -- email variables --
objMail.To = "909.net"
objMail.Cc = Trim(AgentEmail)
objMail.From = Trim(strEmail)
objMail.Subject = "Feedback "
objMail.BodyFormat = "0" ' HTML format
objMail.Body = "First Name: " & Trim(strName) & vbCrLf _
& "Last Name: " & (strLName) & vbCrLf _
& "Company: " & Trim(strCompany) & vbCrLf _
& "Position: " & Trim(strPosition) & vbCrLf _
& "Street: " & Trim(strStreet) & vbCrLf _
& "City: " & Trim(strCity) & vbCrLf _
& "State: " & Trim(strState) & vbCrLf _
& "Zip: " & Trim(strZip) & vbCrLf _
& "Country: " & Trim(optCountry) & vbCrLf _
& "E-Mail Address: " & Trim(strEmail) & vbCrLf _
& "Area Code: " & Trim(strArea) & vbCrLf _
& "Phone: " & Trim(strPhone) & vbCrLf _
& "Interest in Purchasing Residence: " & Trim(strProp) & vbCrLf _
& "Interest in Listing a Property: " & Trim(strList) & vbCrLf _
& "Interest in Rentals: " & Trim(strRental) & vbCrLf _
& "Interest in Commercial: " & Trim(strCommercial) & vbCrLf _
& "Interest in Magazine: " & Trim(strMag) & vbCrLf _
& "Interest in Newsletter: " & Trim(strNewsletter) & vbCrLf _
& "Timeframe: " & Trim(optTimeframe) & vbCrLf _
& "Property Type: " & Trim(optProptype) & vbCrLf _
& "AgentEmail: " & Trim(AgentEmail) & vbCrLf _
& "AgentName: " & Trim(AgentName) & vbCrLf _
& "MLS Number: " & Trim(varMLS) & vbCrLf _
& "Message: " & Trim(strMessage)

' -- send the email --
objMail.Send

' -- clean up object
Set objMail = Nothing

' -- execute confirmation page
Response.Redirect "thanks3.asp"
%>
 
A form method of POST puts the elements into the body of the HTTP request rather than in the QueryString.

So, if your form has a textbox element named Foo, and the form method is GET, then you can find the submitted value like this:
MyVal = Request.QueryString("Foo")

But if the form method is POST, you do this:
MyVal = Request.Form("Foo")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top