in my website I have a couple of forms that you can only see them if certain conditions are applied.
for example - if you're an admin and you search a user, you'll see a form which allows you to edit his information. if you're not you won't see it.
if you're already logged in you can't see the registration form, but if you aren't you can.
so I did it with ASP in this way - (this is the registration part)
if (Session["LoggedIn"] != null)
{
Response.Write("You're already registered!");
}
else
{
Response.Write();
}
I've managed to put in the form inside the Response.Write(), and it also has the javascript part like this -
+ "<script type='text/javascript' src=ValidateData.js>" + "</script>"
this works perfectly fine.
now, I've done this twice. the example above is from the registration part which doesn't allow a logged in user to register again.
I'm having problems with the second one - not showing the edit form to a user who can't edit.
this is basically the code -
if (Session["LoggedIn"] != null && ((Session["IsAdmin"] != null) || (Request.QueryString["SelfEdit"] == "Yes") || ((string)(Session["LoggedIn"]) == UserId)))
{
Response.Write(
"<script type='text/javascript' src='ValidateData2.js'>"
+ "</script>"
+"<form id='form1' name='form1' action='UpdateData.aspx' method='post' onsubmit='return validateForm(this)>"
+ "First name: "+ "<input id='Fname' name='Fname' type='text'>"
+ "<br>"
+ "Last name: " + "<input id='Lname' name='Lname' type='text'>"
+ "<br>"
+ "Password: " + "<input id='Password' name='Password' type='password'>"
+ "<br>"
+ "Validate pass: " + "<input id='pass2' name='pass2' type='password'>"
+ "<br>"
+ "Email: " + "<input id='Email' name='Email' type='text'>"
+ "<br>"
+ "Age: " + "<input id='Age' name='Age' type='text'>"
+ "<br>"
+ "<input id='Submit1' type='submit' value='Edit!' />"
+ "</form>"
);
this is the ValidateData2.js -
function validateForm(form1) {
if (form1.Password.value > 0) {
if (form1.pass2.value.length == 0) {
alert("Please validate password");
return false;
}
if (form1.Password.value != form1.pass2.value) {
alert("Please enter matching passwords!");
return false;
}
if (form1.Password.value.length < 6) {
alert("Passwords are too short!");
return false;
}
}
if (form1.Email.value > 0) {
if (form1.Email.value.indexOf('@') == -1) {
alert("Email must have '@'");
return false;
}
if (form1.Email.value.indexOf('.') == -1) {
alert("Email must have '.'");
return false;
}
if (form1.Email.value.length < 3) {
alert("Please enter a proper email address");
return false;
}
}
if (form1.Age.value> 0) {
if (isNaN(form1.Age) == true) {
alert("Age must be in numbers!");
return false;
}
}
return true;
}
now this doesn't do anything... the submit button just ignores the JS file and just submits the form the way it is, unlike the other form which is written pretty much in the same way except for other JS fields/text boxes.
any ideas? did I miss anything?
I know the code is written really poorly but thats unfortunately what we've been taught in class and thats all I know.
help would be really really appreciated!
thanks!
*I'm not checking for nulls because if a field is empty it means the information won't be edited.
This post has been edited by svpam123: 08 June 2011 - 03:47 AM

New Topic/Question
Reply


MultiQuote






|