Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 21st, 2009, 05:07 PM
Authorized User
Points: 395, Level: 6
Points: 395, Level: 6 Points: 395, Level: 6 Points: 395, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: London, , United Kingdom.
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default text field values

i have two asp pages: default.asp AND friends.asp

Friends.asp

Contain some text fields that ask for user input and then on submit it post the data to the page default.asp

<form id="friends" method="post" action="default.asp">

default.asp


this page retrieve all the data and then store in database.

Now the problem is i am also doing some validation on friends.asp page, hence in case of any error the user has to enter the text again but during this validation i loose the text field data that user entered So IS THEIR ANY EASY WAY SO THE WHEN THE PAGE LOAD AGAIN THE PREVIOUS VALUES REMAIN IN THE TEXT FIELDS?

Many thanks
__________________
Cheers
Sheraz
  #2 (permalink)  
Old January 21st, 2009, 05:55 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Can you explain what KIND of validation you are doing on the FRIENDS.ASP page???

Are you using Javascript in the browser? Or ASP code?

Because if you are using ASP code to validate, then I don't see how you can be using

<form id="friends" method="post" action="default.asp">

And if you are using JS in the browser, then the form fields should not be cleared out until you allow the submit of the form to take place.

Yes, this is actually pretty easy to do, but it depends on how your code works now.
  #3 (permalink)  
Old January 21st, 2009, 06:01 PM
Authorized User
Points: 395, Level: 6
Points: 395, Level: 6 Points: 395, Level: 6 Points: 395, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: London, , United Kingdom.
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default

thanks for reply...

i am using asp code and doing simple validation like check for special characters in name field....Thanks
__________________
Cheers
Sheraz

Last edited by Sheraz Khan; January 21st, 2009 at 06:11 PM..
  #4 (permalink)  
Old January 21st, 2009, 06:51 PM
Friend of Wrox
Points: 489, Level: 7
Points: 489, Level: 7 Points: 489, Level: 7 Points: 489, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Berkshire, United Kingdom.
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Sheraz,

If i have read your post correctly one way to solve your issue is with the use of sessions.

Re-learnt recently in the Thread - Retreival of values from History in ASP on page two of this forum.

So a simple

Code:
FrmName=Request.Form("FrmName")
Session("FrmName") = FrmName
Pre your asp checks should do the trick.
  #5 (permalink)  
Old January 21st, 2009, 07:03 PM
Authorized User
Points: 395, Level: 6
Points: 395, Level: 6 Points: 395, Level: 6 Points: 395, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: London, , United Kingdom.
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default

hi
cant i use hidden field some how?
__________________
Cheers
Sheraz
  #6 (permalink)  
Old January 21st, 2009, 07:48 PM
Friend of Wrox
Points: 489, Level: 7
Points: 489, Level: 7 Points: 489, Level: 7 Points: 489, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Berkshire, United Kingdom.
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Sheraz,

Unsure - Re the use of hidden fields what you are trying to achieve.

Ref:

Quote:
So IS THEIR ANY EASY WAY SO THE WHEN THE PAGE LOAD AGAIN THE PREVIOUS VALUES REMAIN IN THE TEXT FIELDS?
The example below is essentially how i have achieved this as per advice from Old Pedant in previous Thread.

Friends.asp

Code:
<form id="friends" method="post" action="default.asp">
<p>Name</p><input name="FrmName" type="text" value="<%Response.Write(Session("FrmName"))%>">
<input type="submit" name="submit" value"You'd De Man">
</form>
Default.asp

Code:
FrmName=Request.Form("FrmName")
Session("FrmName") = FrmName
 
If Instr(FrmName,"Doh!") > 0 then
Response.Redirect("Friends.asp")
Else
Session("FrmName") = ""
End If
I'm sure there are several neater solutions but as the name suggests i am fairly draconian in my logic.

Cheers

Aspless
  #7 (permalink)  
Old January 21st, 2009, 07:57 PM
Authorized User
Points: 395, Level: 6
Points: 395, Level: 6 Points: 395, Level: 6 Points: 395, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: London, , United Kingdom.
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default

thanks but i dont want to use sessions cuz of extra load of server SO is it possible by any other way?


many thanks
__________________
Cheers
Sheraz
  #8 (permalink)  
Old January 21st, 2009, 08:04 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
Originally Posted by Sheraz Khan View Post
i am using asp code and doing simple validation like check for special characters in name field...
But you said you are doing that validation in Friends.asp

Yet you show your code as
Code:
        <form id="friends" method="post" action="default.asp">
THAT MAKES NO SENSE. *HOW* can your <FORM> post to default.asp and yet you still do the validation in the FIRST PAGE????

Again, I ask you: *SHOW SOME CODE*.

If you care, here is how I would do it:
Code:
<%
' *** THIS IS THE friends.asp PAGE ***
If Trim(Request.Form("POSTBACK")) = "YES" Then
    ' validate the form here
    ' example:
    Set reAlphaOnly = New RegExp
    reAlphaOnly.Pattern = "[^a-zA-Z]"
    Set reNumOnly = New RegExp
    reNumOnly.Pattern = "[^0-9]"

    oops = ""

    If reAlphaOnly.Test( Trim(Request.Form("UserName") ) Then 
        oops = oops & "<li>Invalid characters in username</li>"
    End If
    If reNumOnly.Test( Trim(Request.Form("Age") ) Then
        oops = oops & "<li>Age must be digits only</li>"
    End If
    ' (other fields could be done similarly)
    
    If oops = "" Then Server.Transfer "default.asp"
End If
%>
<BODY>
... heading stuff...
<% If oops <> "" Then Response.Write "Errors: <ul class=errors>" & oops & "</ul>" %>
....
<FORM method=post> <!-- OMIT the action= so form posts to this same page -->
<input type=hidden name="POSTBACK" value="YES">

username: <INPUT Name="UserName" Value="<%=Request.Form("UserName")%>" >
age: <INPUT Name="Age" Value="<%=Request.Form("Age")%>" >
...
<INPUT Type=Submit>
</form>
The "trick" here is Server.Transfer. When you use that, the transferred-to page receives the *SAME* Request.Form and Request.QueryString values as the page you are currenly on.
  #9 (permalink)  
Old January 21st, 2009, 08:12 PM
Authorized User
Points: 395, Level: 6
Points: 395, Level: 6 Points: 395, Level: 6 Points: 395, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: London, , United Kingdom.
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Here is my code:

Friends.asp

<div id="Refer">

<form id="friends" method="post" action="/Join-the-club/Tell-your-friend/default.asp?BtyFirst=False">

<div id="exp">
<h2><span></span>Tell your friends</h2>
<%
Dim sUserInfoErrorFlags
'sUserInfoErrorFlags =""

%>
</div>

<% ' **********************************About you Start********************************************* ******--> %>
<fieldset>
<h4 class="lAbout"><span></span>About You</h4>

<p>
<label for="iRName">Your name</label>
<input type="text" class="text" id="iRName" maxlength="100" name="iRName" value="<%=iRName%>" />
</p>

<p class="iREmail">
<label for="iREmail">Email address</label>
<input type="text" class="text" id="iREmail" name="iREmail" maxlength="100" value="<%=iREmail%>" />
<%

If InStr(sUserInfoErrorFlags, "|EMAIL|") > 0 Then Response.Write ( "<label class='error' for='iREmail'>Please provide a valid email address.</label>") End If %>

</p>

<!--############# FRIENDS DETAILS ################# -->


<h4 class="iFriends"><span></span>Your Friends</h4>
<p>
<label for="iFName1">Friend's name</label>
<input type="text" class="text" id="iFName1" maxlength="50" name="iFName1" value="<%=iFName1%>" />
<% If InStr(sUserInfoErrorFlags, "|Name0|") >0 Then Response.Write "<label class='error' for='iFName1'>Please enter your name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|NameInvalid0|") >0 Then Response.Write "<label class='error' for='iFName1'>Please enter a valid first name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FADMIN0|") >0 Then Response.Write "<label class='error' for='iFName1'>Name contain word 'Admin'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FCOMM0|") >0 Then Response.Write "<label class='error' for='iFName1'>Name contain word 'Community'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FBOU0|") >0 Then Response.Write "<label class='error' for='iFName1'>Name contain word 'Bounty'</label>" End If %>
</p>

<p class="iFEmail1">
<label for="iFEmail1">Email address</label>
<input type="text" class="text" id="iFEmail1" name="iFEmail1" maxlength="100" value="<%=iFEmail1%>" />

<%

If InStr(sUserInfoErrorFlags, "|FEMAIL1|") > 0 Then Response.Write ( "<label class='error' for='iFEmail1'>Please provide a valid email address.</label>") End If %> </p>

<p>
<label for="iFName2">Friend's name</label>
<input type="text" class="text" id="iFName2" maxlength="50" name="iFName2" value="<%=iFName2%>" />
<% If InStr(sUserInfoErrorFlags, "|Name1|") >0 Then Response.Write "<label class='error' for='iFName2'>Please enter your name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|NameInvalid1|") >0 Then Response.Write "<label class='error' for='iFName2'>Please enter a valid first name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FADMIN1|") >0 Then Response.Write "<label class='error' for='iFName2'>Name contain word 'Admin'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FCOMM1|") >0 Then Response.Write "<label class='error' for='iFName2'>Name contain word 'Community'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FBOU1|") >0 Then Response.Write "<label class='error' for='iFName2'>Name contain word 'Bounty'</label>" End If %>
</p>

<p class="iFEmail2">
<label for="iFEmail2">Email address</label>
<input type="text" class="text" id="iFEmail2" name="iFEmail2" maxlength="100" value="<%=iFEmail2%>" />

<%

If InStr(sUserInfoErrorFlags, "|FEMAIL2|") > 0 Then Response.Write ( "<label class='error' for='iFEmail2'>Please provide a valid email address.</label>") End If %> </p>

<p>
<label for="iFName3">Friend's name</label>
<input type="text" class="text" id="iFName3" maxlength="50" name="iFName3" value="<%=iFName3%>" />
<% If InStr(sUserInfoErrorFlags, "|Name2|") >0 Then Response.Write "<label class='error' for='iFName3'>Please enter your name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|NameInvalid2|") >0 Then Response.Write "<label class='error' for='iFName3'>Please enter a valid first name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FADMIN2|") >0 Then Response.Write "<label class='error' for='iFName3'>Name contain word 'Admin'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FCOMM2|") >0 Then Response.Write "<label class='error' for='iFName3'>Name contain word 'Community'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FBOU2|") >0 Then Response.Write "<label class='error' for='iFName3'>Name contain word 'Bounty'</label>" End If %>
</p>

<p class="iFEmail3">
<label for="iFEmail3">Email address</label>
<input type="text" class="text" id="iFEmail3" name="iFEmail3" maxlength="100" value="<%=iFEmail3%>" />

<%
'response.Write(sUserInfoErrorFlags)
If InStr(sUserInfoErrorFlags, "|FEMAIL3|") > 0 Then Response.Write ( "<label class='error' for='iFEmail3'>Please provide a valid email address.</label>") End If %> </p>

<p>
<label for="iFName4">Friend's name</label>
<input type="text" class="text" id="iFName4" maxlength="50" name="iFName4" value="<%=iFName4%>" />
<% If InStr(sUserInfoErrorFlags, "|Name3|") >0 Then Response.Write "<label class='error' for='iFName4'>Please enter your name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|NameInvalid3|") >0 Then Response.Write "<label class='error' for='iFName4'>Please enter a valid first name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FADMIN3|") >0 Then Response.Write "<label class='error' for='iFName4'>Name contain word 'Admin'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FCOMM3|") >0 Then Response.Write "<label class='error' for='iFName4'>Name contain word 'Community'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FBOU3|") >0 Then Response.Write "<label class='error' for='iFName4'>Name contain word 'Bounty'</label>" End If %>
</p>

<p class="iFEmail4">
<label for="iFEmail4">Email address</label>
<input type="text" class="text" id="iFEmail4" name="iFEmail4" maxlength="100" value="<%=iFEmail4%>" />

<%

If InStr(sUserInfoErrorFlags, "|FEMAIL4|") > 0 Then Response.Write ( "<label class='error' for='iFEmail4'>Please provide a valid email address.</label>") End If %></p>

<p>
<label for="iFName5">Friend's name</label>
<input type="text" class="text" id="iFName5" maxlength="50" name="iFName5" value="<%=iFName5%>" />
<% If InStr(sUserInfoErrorFlags, "|Name4|") >0 Then Response.Write "<label class='error' for='iFName5'>Please enter your name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|NameInvalid4|") >0 Then Response.Write "<label class='error' for='iFName5'>Please enter a valid first name.</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FADMIN4|") >0 Then Response.Write "<label class='error' for='iFName5'>Name contain word 'Admin'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FCOMM4|") >0 Then Response.Write "<label class='error' for='iFName5'>Name contain word 'Community'</label>" End If %>
<% If InStr(sUserInfoErrorFlags, "|FBOU4|") >0 Then Response.Write "<label class='error' for='iFName5'>Name contain word 'Bounty'</label>" End If %>
</p>

<p class="iFEmail5">
<label for="iFEmail5">Email address</label>
<input type="text" class="text" id="iFEmail5" name="iFEmail5" maxlength="100" value="<%=iFEmail5%>" />

<%

If InStr(sUserInfoErrorFlags, "|FEMAIL5|") > 0 Then Response.Write ( "<label class='error' for='iFEmail5'>Please provide a valid email address.</label>") End If %> </p>










<% '********************************************End Referal ************************************************** ** %>
<p>
<input id="submit" name="submit" class="submit" type="image" value="Submit" src="/join-the-club/i/submitOff.jpg" />
</p>


</fieldset>


</form>
</div>

default.asp


<!-- #include virtual="/join-the-club/inc/Utility.asp" -->


<%

''form Parameter
On Error Resume Next

Dim iRName,iREmail, FName, FEmail, FNameArray(4),FEmailArray(4),i,x
' Dim error variables
Dim qryBtyFirst
'Dim sUserInfoErrorFlags

sUserInfoErrorFlags=""
'' Retrive form fields
'dim test
'response.Write(request.Form("iFName1"))
'response.Write(request.Form("iFName2"))
'response.Write(request.Form("iFName3"))
'response.Write(request.Form("iFName4"))
'response.Write(request.Form("iFName5"))

'response.Write(session("name"))

iRName = trim(request.Form("iRName"))
iREmail = trim(request.Form("iREmail"))
FNameArray(0) = trim(request.Form("iFName1"))
FEmailArray(0) = trim(request.Form("iFEmail1"))
FNameArray(1) = trim(request.Form("iFName2"))
FEmailArray(1) = trim(request.Form("iFEmail2"))
FNameArray(2) = trim(request.Form("iFName3"))
FEmailArray(2) = trim(request.Form("iFEmail3"))
FNameArray(3) = trim(request.Form("iFName4"))
FEmailArray(3) = trim(request.Form("iFEmail4"))
FNameArray(4) = trim(request.Form("iFName5"))
FEmailArray(4) = trim(request.Form("iFEmail5"))



''Btyfirst is for user come first time to this form So that it wont display any validation errors
qryBtyFirst=trim(Request.QueryString("btyFirst"))
if qryBtyFirst="" then
qryBtyFirst=True
else
qryBtyFirst= qryBtyFirst


end if


' VALIDATION STARTS HERE
'response.Write(qryBtyFirst)
if UCASE(qryBtyFirst) <> "TRUE" then

' EMAIL ADRRESS VALIDATION STARTS HERE

if IsEmail(iREmail)=false then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|EMAIL|"
End if

'if InStr(sUserInfoErrorFlags, "|NameInvalid|") >0
if IsEmail(FEmailArray(0))=false AND len(FEmailArray(0)) > 0 then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FEMAIL1|"
End if

if IsEmail(FEmailArray(1))=false AND len(FEmailArray(1)) > 0 then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FEMAIL2|"
End if

if IsEmail(FEmailArray(2))=false AND len(FEmailArray(2)) > 0 then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FEMAIL3|"
End if

if IsEmail(FEmailArray(3))=false AND len(FEmailArray(3)) > 0 then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FEMAIL4|"
End if

if IsEmail(FEmailArray(4))=false AND len(FEmailArray(4)) > 0 then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FEMAIL5|"
End if


' EMAIL ENDS HERE

' NAME VALIDATION STARTS HERE
dim z
for z=0 to 4

if len(FNameArray(z)) = 1 then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|Name" & z & "|"
end if
''
''Name must be alphabased
''
if IsAlpha(FNameArray(z)) = false then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|NameInvalid" & z & "|"
end if

if IsMatch("ADMIN",FNameArray(z)) = true then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FADMIN" & z & "|"
end if
if IsMatch("COMMUNITY",FNameArray(z)) = true then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FCOMM" & z & "|"
end if
if IsMatch("BOUNTY",FNameArray(z)) = true then
sUserInfoErrorFlags = sUserInfoErrorFlags & "|FBOU" & z & "|"
end if

next

' NAME ENDS HERE







response.Write(sUserInfoErrorFlags)

end if

'VALIDATION ENDS HERE





%>




<p>
Error details:
</p>
<table border="1">
<tr>
<td>Err.Source</td>
<td><%= Err.Source %></td>
</tr>
<tr>
<td>Err.Number</td>
<td><%= Err.Number %></td>
</tr>
<tr>
<td>Err.Description</td>
<td><%= Err.description %></td>
</tr>

</table>



<!--#include file="friends.asp"-->
__________________
Cheers
Sheraz
  #10 (permalink)  
Old January 21st, 2009, 08:32 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

AHA! *HERE* is the trick to why that code works!!!

Code:
<!--#include file="friends.asp"-->
So what happens is, when your <FORM> posts to "default.asp", your default.asp page actually is *THE SAME PAGE* as "friends.asp" !!!

Okay...sneaky.

But that *ALSO* means that what I showed you WILL WORK!!!

But now that I look at your code, you are ALREADY DOING THAT!
Code:
<input type="text" class="text" id="iFEmail1" name="iFEmail1" maxlength="100" value="<%=iFEmail1%>" />
So I do not see whey this isn't working for you, already.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Text(Sql Server Text Field) to Image(JPG) srinivas72 ADO.NET 2 February 13th, 2009 06:31 PM
get the values of form field values crmpicco Perl 2 March 16th, 2007 10:57 AM
Selecting on different values of the same field alphahamster SQL Language 4 May 30th, 2006 11:08 AM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 5th, 2005 11:33 PM
Pass select values to hidden text field? abq23 Javascript How-To 2 July 20th, 2004 09:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.