Log in

View Full Version : Is this possible?



bjf98
01-15-2008, 10:05 PM
Hey guys.
Is there a javascript or other serverside script out there that will allow me to check and see if a required form element has a certain value?

Here is my current code, it might give you a lead to what I mean:



<form action="netxpage.php">
ID:&nbsp;&nbsp;<input type="text" name="id"><br>
// This field requires the validation, it must have a certain value in it for the
//user to procede.
<input type="submit" value="Continue">
</form>

Master_script_maker
01-15-2008, 11:29 PM
yes of course. would you prefer it javascript(client) or php(server) (i would choose php, almost impossible to trick)? what do you want the syntax to be? e.g. xxx-xxx-xxx or xxxxxxxxx or only letters or only numbers or a combination of both?

bjf98
01-15-2008, 11:46 PM
How about php with a santax of xxxxxxxxx and only #'s.

Master_script_maker
01-16-2008, 11:00 PM
script changed
your form(must be .php):


<form action="validate.php" method="post">
<div style="color: red"><?php if ($error) { echo $error; } ?></div>
ID:&nbsp;&nbsp;<input type="text" name="id"><br>
<input type="submit" value="Continue">
</form>
validate.php:

<?php
$nextpage=""; //the page to go to if there are no errors e.g. nextpage.php
$formpage=""; //the form page
$string = $_POST['id'];
if ($string==null) {
$error = "You did not enter anything.";
} else {
if (!eregi('^[0-9]{9}$', $string)) {
$error = "'$string' is not a valid id.";
}
}
if ($error == null) {
echo "<script type=\"text/javascript\">
window.location=\"".$nextpage."\";
</script>
<p>If you were not redirected click <a href=\"".$nextpage."\">here.</a></p>";
} else {
include($formpage);
}
?>

bjf98
01-19-2008, 01:11 PM
Tks!
Uh.. where does the valid id get entered in the script?

Master_script_maker
01-19-2008, 01:19 PM
do you mean where the script gets the content of the ip input, or the form?

bjf98
01-19-2008, 02:52 PM
the id that has to match the one the user enters

Master_script_maker
01-19-2008, 09:27 PM
i think i misinterpreted your fist post. you wanted to use the id to login?

TimFA
01-19-2008, 10:14 PM
Does he just want something like:



$id=$_POST['id'];

if ($id=="1232343") {
print("
<head>
<script type=\"javascript\">
window.location='nextpage.html';
</script>
<body>
</body>");
}

else {
print("
<head>
<script type=\"javascript\">
setTimeOut("window.location='javascript.go:history(-1)'",5000);
</script>
<body>
ID wrong, please try again.
</body>
}


Then a form as so:



<form action="thephp.php" method="post">
<input type="text" name="id" value="Type ID in here.">
<input type="submit" value="Check ID">
</form>


That is very simple, should work just fine for 1, 2, 3, up to maybe 6 IDs but if more then you shouldn't use this method most likely.
Also someone had best check to make sure the "javascript.go:history(-1) is right, I believe it is but I can't be sure.

Tim

bjf98
01-21-2008, 12:19 PM
Hi Tim
Tks for the script, but there seems to be a error in line 18.
Here is the error code:
Parse error: syntax error, unexpected T_STRING in /***/****/***/***/***/thephp.php on line 18

TimFA
01-21-2008, 04:46 PM
I'm sorry, here I forgot the last ")



$id=$_POST['id'];

if ($id=="1232343") {
print("
<html>
<head>
<script type=\"text/javascript\">
setTimeOut(\"window.location='nextpage.html'\",1);
</script>
</head>
<body>
</body>
</html>
");
}

else {
print("
<html>
<head>
<script type=\"text/javascript\">
setTimeOut(\"window.location='javascript.go:history(-1)'\",5000);
</script>
</head>
<body>
ID wrong, please try again.
</body>
</html>
");
}


EDIT: please completely recopy the code, I made some coding errors and a full copy is needed. I can't seem to get the redirect working but maybe its just me. Anyways the PHP part works now.

bjf98
01-23-2008, 09:07 PM
I edited the script a little so it would work:

<?php
$id=$_POST['id'];

if ($id=="1232343") {
print("
<html>
<head>
</head>
<body>
<a href='register.cgi'>Go Foward</a>
</body>
</html>
");
}

else {
print("
<html>
<head>
</head>
<body>
ID wrong, please try again.<br>
<a href='javascript:history.go(-1)'>Go Back</a>
</body>
</html>
");
}
?>

TimFA
01-24-2008, 12:22 AM
I don't use that function much, so excuse my JavaScript mistakes. Hope it works.

Tim

Nile
01-24-2008, 12:38 AM
Scratch what I jist said nvrmnd.