subgenius
asked on
ASP page with javascript validation
This is continued from https://www.experts-exchange.com/questions/20544030/how-to-pass-user-input-value-to-a-new-web-page.html
I have this code working now and would like to have a confirmation page show after this page is submitted. As it is now, this is what shows after Submit:
form_ok = True
email = someone@xyz.com
fname = John
lname = Doe
submit = Submit
newemail = jdoe@xyz.com
gladxml had the comment "'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form" but I'm not sure how to use server.transfer to call the next page and pass the values i want to show.
************************** ********** ********** ***
<%
if request.form("form_ok") = "True" then
Response.Buffer = true
dim cnn,rst
dim strConn
dim rscheck
set cnn = Server.CreateObject("ADODB .Connectio n")
cnn.open "Provider=OraOLEDB.Oracle; Data Source=xxx; User Id=xxx; Password=xxx"
set rscheck = Server.CreateObject("ADODB .RecordSet ")
'KIndly double check if this is the sql is correct...
strQuot=Chr(39)
sql1 = "SELECT * FROM tablename WHERE email_addr ='" & request("email") & "'"
set rscheck = cnn.execute(sql1)
if not (rscheck.eof) then
set rst = Server.CreateObject("ADODB .RecordSet ")
strQuot=Chr(39)
sql = "UPDATE tablename SET " & "firstname =" & strQuot & Request.Form("fname") & strQuot & ", " & "lastname=" &
strQuot & Request.Form("lname") & strQuot & ", " & "email_addr=" & strQuot & Request.Form("newemail") & strQuot & "WHERE
email_addr=" & strQuot & Request.Form("email") & strQuot
set rst = cnn.execute(sql)
'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
response.end
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
else
errmsg = "Please check email address entered... No record found..."
end if
end if
%>
<html>
<head>
<title>
Email Address Update
</title>
</head>
<body>
<form name="inputform" method="Post" action="email-update.asp" Onsubmit="return validate(this)"><br>
<input type="hidden" name="form_ok" value="False">
ENTER OLD EMAIL ADDRESS<br>
<input type="text" name="email" size="50" value="<%=request.form("em ail")%>">< %=errmsg%> <br>
ENTER NEW FIRST NAME<br>
<input type="text" name="fname" size="30" value="<%=request.form("fn ame")%>">< br>
ENTER NEW LAST NAME<br>
<input type="text" name="lname" size="30" value="<%=request.form("ln ame")%>">< br>
ENTER NEW EMAIL ADDRESS<br>
<input type="text" name="newemail" size="50" value="<%=request.form("ne wemail")%> "><br>
<input type="submit" value="Submit" name="submit"></form>
</body>
<script language="JavaScript">
<!--
function verifyEmail(frmEmailAdd)
{
invalidChars = " /:,;";
if (frmEmailAdd == "") {
return false;
}
for (i = 0; i < invalidChars.length; i++) {
badChar = invalidChars.charAt(i);
if (frmEmailAdd.indexOf(badCh ar, 0) > -1) {
return false;
}
}
atPos = frmEmailAdd.indexOf("@", 1);
if (atPos == -1) {
return false;
}
if (frmEmailAdd.indexOf("@", (atPos + 1)) > -1) {
return false;
}
periodPos = frmEmailAdd.indexOf(".", atPos);
if (periodPos == -1) {
return false;
}
if ((periodPos + 3) > frmEmailAdd.length) {
return false;
}
return true;
}
function validate()
{
if (!verifyEmail(document.inp utform.ema il.value)) {
alert("Invalid email address... Kindly check old email address");
document.inputform.email.f ocus();
document.inputform.email.s elect();
return false;
}
if (document.inputform.fname. value == "") {
alert("You must enter a First Name");
document.inputform.fname.f ocus();
return false;
}
if (document.inputform.lname. value == "") {
alert("You must enter a Last Name");
document.inputform.lname.f ocus();
return false;
}
if (!verifyEmail(document.inp utform.new email.valu e)) {
alert("Invalid email address... Kindly check new email address.");
document.inputform.newemai l.focus();
document.inputform.newemai l.select() ;
return false;
}
document.inputform.form_ok .value="Tr ue";
return true;
}
// -->
</script>
</html>
I have this code working now and would like to have a confirmation page show after this page is submitted. As it is now, this is what shows after Submit:
form_ok = True
email = someone@xyz.com
fname = John
lname = Doe
submit = Submit
newemail = jdoe@xyz.com
gladxml had the comment "'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form" but I'm not sure how to use server.transfer to call the next page and pass the values i want to show.
**************************
<%
if request.form("form_ok") = "True" then
Response.Buffer = true
dim cnn,rst
dim strConn
dim rscheck
set cnn = Server.CreateObject("ADODB
cnn.open "Provider=OraOLEDB.Oracle;
set rscheck = Server.CreateObject("ADODB
'KIndly double check if this is the sql is correct...
strQuot=Chr(39)
sql1 = "SELECT * FROM tablename WHERE email_addr ='" & request("email") & "'"
set rscheck = cnn.execute(sql1)
if not (rscheck.eof) then
set rst = Server.CreateObject("ADODB
strQuot=Chr(39)
sql = "UPDATE tablename SET " & "firstname =" & strQuot & Request.Form("fname") & strQuot & ", " & "lastname=" &
strQuot & Request.Form("lname") & strQuot & ", " & "email_addr=" & strQuot & Request.Form("newemail") & strQuot & "WHERE
email_addr=" & strQuot & Request.Form("email") & strQuot
set rst = cnn.execute(sql)
'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
response.end
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
else
errmsg = "Please check email address entered... No record found..."
end if
end if
%>
<html>
<head>
<title>
Email Address Update
</title>
</head>
<body>
<form name="inputform" method="Post" action="email-update.asp" Onsubmit="return validate(this)"><br>
<input type="hidden" name="form_ok" value="False">
ENTER OLD EMAIL ADDRESS<br>
<input type="text" name="email" size="50" value="<%=request.form("em
ENTER NEW FIRST NAME<br>
<input type="text" name="fname" size="30" value="<%=request.form("fn
ENTER NEW LAST NAME<br>
<input type="text" name="lname" size="30" value="<%=request.form("ln
ENTER NEW EMAIL ADDRESS<br>
<input type="text" name="newemail" size="50" value="<%=request.form("ne
<input type="submit" value="Submit" name="submit"></form>
</body>
<script language="JavaScript">
<!--
function verifyEmail(frmEmailAdd)
{
invalidChars = " /:,;";
if (frmEmailAdd == "") {
return false;
}
for (i = 0; i < invalidChars.length; i++) {
badChar = invalidChars.charAt(i);
if (frmEmailAdd.indexOf(badCh
return false;
}
}
atPos = frmEmailAdd.indexOf("@", 1);
if (atPos == -1) {
return false;
}
if (frmEmailAdd.indexOf("@", (atPos + 1)) > -1) {
return false;
}
periodPos = frmEmailAdd.indexOf(".", atPos);
if (periodPos == -1) {
return false;
}
if ((periodPos + 3) > frmEmailAdd.length) {
return false;
}
return true;
}
function validate()
{
if (!verifyEmail(document.inp
alert("Invalid email address... Kindly check old email address");
document.inputform.email.f
document.inputform.email.s
return false;
}
if (document.inputform.fname.
alert("You must enter a First Name");
document.inputform.fname.f
return false;
}
if (document.inputform.lname.
alert("You must enter a Last Name");
document.inputform.lname.f
return false;
}
if (!verifyEmail(document.inp
alert("Invalid email address... Kindly check new email address.");
document.inputform.newemai
document.inputform.newemai
return false;
}
document.inputform.form_ok
return true;
}
// -->
</script>
</html>
ASKER
This page submits to itself and displays:
form_ok = True
email = someone@xyz.com
fname = John
lname = Doe
submit = Submit
newemail = jdoe@xyz.com
I want it to display something more meaningful to the user. For example:
The record for "someone@xyz.com" has been updated to:
Email Address "jdoe@xyz.com"
First Name John
Last Name Doe
In other words, I want to format the output as html on a second page instead of the page submitting to itself. Or have it submit to itself and display the results as I mentioned above rather that the way it displays now.
form_ok = True
email = someone@xyz.com
fname = John
lname = Doe
submit = Submit
newemail = jdoe@xyz.com
I want it to display something more meaningful to the user. For example:
The record for "someone@xyz.com" has been updated to:
Email Address "jdoe@xyz.com"
First Name John
Last Name Doe
In other words, I want to format the output as html on a second page instead of the page submitting to itself. Or have it submit to itself and display the results as I mentioned above rather that the way it displays now.
Sounds like all you need to do is change your response.write information to show what you are trying to show in your note here.
==== original code that runs if you are doing an update ===
First you do all your database stuff then you come upon your code here.
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
' response.end 'need to get rid of this until you show all the information you want to show.
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
---- eof ----
first, let's get rid of that response.end until you show all your information.
Instead of the for each fld in request.form which is just a generic way of showing all the information passed from the form, we can show what you want to show
Such as:
---- BOF ----
Response.write("The record for """ & request.form("email") & """ has been updated to:" & "<BR>")
Response.write("Email Address:" & request.form("newemail") & "<BR>")
Response.write("First Name:" & request.form("fname") & "<BR>")
Response.write("Last Name:" & request.form("lname") & "<BR>")
---- EOF ----
Dan M.
dmstrat@yahoo.com
==== original code that runs if you are doing an update ===
First you do all your database stuff then you come upon your code here.
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
' response.end 'need to get rid of this until you show all the information you want to show.
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
---- eof ----
first, let's get rid of that response.end until you show all your information.
Instead of the for each fld in request.form which is just a generic way of showing all the information passed from the form, we can show what you want to show
Such as:
---- BOF ----
Response.write("The record for """ & request.form("email") & """ has been updated to:" & "<BR>")
Response.write("Email Address:" & request.form("newemail") & "<BR>")
Response.write("First Name:" & request.form("fname") & "<BR>")
Response.write("Last Name:" & request.form("lname") & "<BR>")
---- EOF ----
Dan M.
dmstrat@yahoo.com
subgenius,
To explain it further...
On the page that you has posted... Kindly delete this lines
=====
'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
response.end
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
=====
then replace it with the line below
====
server.transfer("confirm.a sp")
====
Now this will be the second page... which is the
confirm.asp
======just cut and paste and save this as confirm.asp
<%
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
response.end
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
%>
HTH...
HAppy programming...
To explain it further...
On the page that you has posted... Kindly delete this lines
=====
'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
response.end
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
=====
then replace it with the line below
====
server.transfer("confirm.a
====
Now this will be the second page... which is the
confirm.asp
======just cut and paste and save this as confirm.asp
<%
for each fld in request.form
response.write fld & " = " & request.form(fld) & "<BR>"
next
response.end
Response.Write "Record updated"
response.write "your old email address was: " & request.form("email") & "<BR>"
response.write "your new email address was: " & request.form("newemail")
%>
HTH...
HAppy programming...
subgenius,
This will meet the requirement that you given above...
save this as confirm.asp
====
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">The record for <%= " " & request.form("email") & " "%> has been updated
to:</td>
</tr>
<tr>
<td width="28%">Email address:</td>
<td width="72%"><%=request.for m("newemai l")%>@</t d>
</tr>
<tr>
<td width="28%">First Name:</td>
<td width="72%"><%=& request.form("fname")%>@< /td>
</tr>
<tr>
<td width="28%">Last Name:</td>
<td width="72%"><%=request.for m("lname") %>@</td>
</tr>
</table>
</body>
</html>
===
Below are related links regarding server.transfer
http://www.devguru.com/Technologies/asp/quickref/server_transfer.html
http://www.w3schools.com/asp/met_transfer.asp
The reason why I used server.transfer cause I am submitting the page to itself... and when you submit it to the same page the request collection will be gone if you will use response.redirect so response.transfer is one solution...
HTH...
HAppy programming...
This will meet the requirement that you given above...
save this as confirm.asp
====
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">The record for <%= " " & request.form("email") & " "%> has been updated
to:</td>
</tr>
<tr>
<td width="28%">Email address:</td>
<td width="72%"><%=request.for
</tr>
<tr>
<td width="28%">First Name:</td>
<td width="72%"><%=& request.form("fname")%>@<
</tr>
<tr>
<td width="28%">Last Name:</td>
<td width="72%"><%=request.for
</tr>
</table>
</body>
</html>
===
Below are related links regarding server.transfer
http://www.devguru.com/Technologies/asp/quickref/server_transfer.html
http://www.w3schools.com/asp/met_transfer.asp
The reason why I used server.transfer cause I am submitting the page to itself... and when you submit it to the same page the request collection will be gone if you will use response.redirect so response.transfer is one solution...
HTH...
HAppy programming...
ASKER
gladxml,
I get the following error with the confirm.asp page added:
Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/poc/confirm.asp, line 19, column 15
I can't find the problem.
Should this line
<form name="inputform" method="Post" action="email-update.asp" Onsubmit="return validate(this)"><br>
have confirm.asp in it instead of email-update.asp?
confirm.asp, line 19 is this:
<td width="72%"><%=& request("fname")%> </td>
Thanks.
I get the following error with the confirm.asp page added:
Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/poc/confirm.asp, line 19, column 15
I can't find the problem.
Should this line
<form name="inputform" method="Post" action="email-update.asp" Onsubmit="return validate(this)"><br>
have confirm.asp in it instead of email-update.asp?
confirm.asp, line 19 is this:
<td width="72%"><%=& request("fname")%> </td>
Thanks.
ASKER
dmstrat,
Thanks.
I tried what you suggested and it did display what I wanted but it also displays the form input boxes and Submit boxes just as they are seen on the first page.
Thanks.
I tried what you suggested and it did display what I wanted but it also displays the form input boxes and Submit boxes just as they are seen on the first page.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
gladxml,
Thanks for all your help. I'm struggling now with adding a new record. If I can't get myself unstuck, I'll post a new question under the title "add new record, Oracle"
Thanks again.
Thanks for all your help. I'm struggling now with adding a new record. If I can't get myself unstuck, I'll post a new question under the title "add new record, Oracle"
Thanks again.
subgenius,
Why a grade of B?
KIndly check out the link below on the grading system.
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
To change the grade you can ask a zero point question on the community support
Below is the link.
https://www.experts-exchange.com/Community_Support/
Regards,
gladxml
Why a grade of B?
KIndly check out the link below on the grading system.
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
To change the grade you can ask a zero point question on the community support
Below is the link.
https://www.experts-exchange.com/Community_Support/
Regards,
gladxml
ASKER
gladxml,
You are absolutely right. Your response did meet the criteria of a "thorough answer" and should be graded as an A. My mistake, I'll request that the grade be changed. Sorry for the confusion. Thanks again.
You are absolutely right. Your response did meet the criteria of a "thorough answer" and should be graded as an A. My mistake, I'll request that the grade be changed. Sorry for the confusion. Thanks again.
Grade change request by subgenius. Changed from B to A.
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
Are you saying you want to pass this info to yet another page?