Welcome to WebmasterWorld Guest from 54.146.240.181

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Newbie question on php validation

is action="<?php echo $PHP_SELF?>"> the way?

     

neiljones

9:17 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



I have come across a number of examples of code using
action="<?php echo $PHP_SELF?>">
to do validation there is an example below.
But thsi just seems to bring the original page back even when the validation is OK.

what I want is a series of PHP pages that validate and then if correct go onto the next page.
I can't seem to find an example that does both.
All I need to see is how it is done. Have I the wrong approach?
<html>
<body>
<?php
if ($submit) {
if ($pword1!= $pword2) {
$error = "Sorry! The passwords you have entered do not match.";
} else {
// process form
echo "Thank You!";
}
if (strlen($pword1) < 4){
$error ="Sorry! Your password must be at least 4 letters long.";
}
}
if (!$submit $error) {
echo $error;
?>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
Enter a user name <input type="text" name="first" value="<?php echo $first?>">
<br>
Choose a password <input type="text" name="pword1" value="<?php echo $pword1?>">
<br>
Renter password <input type="text" name="pword2" value="<?php echo $pword2?>">
<br>
<input type="Submit" name="submit" value="Enter Information">
</form>
<?php
} // end if
?>
</body>
</html>

jatar_k

9:56 pm on Aug 18, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld neiljones,

take a look at this

in your version
if ($pword1!= $pword2) {

if the passwords matched it would say thank you and then do a few more checks. I changed it around a bit. The true test to see if it succeeds is
if (!$submit $error)

I just added an else to this statement and had that send it off to a thank you page using header [ca.php.net].

<?
if ($submit) {
if ($pword1!= $pword2) {
$error = "Sorry! The passwords you have entered do not match.";
}
if (strlen($pword1) < 4){
$error ="Sorry! Your password must be at least 4 letters long.";
}
}
if (!$submit $error) {
echo "<html><body>";
echo $error;
?>
<P>
<form method="post" action="<?= $PHP_SELF?>">
Enter a user name <input type="text" name="first" value="<?= $first?>">
<br>
Choose a password <input type="text" name="pword1" value="<?= $pword1?>">
<br>
Renter password <input type="text" name="pword2" value="<?= $pword2?>">
<br>
<input type="Submit" name="submit" value="Enter Information">
</form>
</body>
</html>
<?
} else {
header("Location: thankyou.html");
}
?>

I didn't test it but I believe thats right. Does that help you understand better? I also used a little shorthand.

<?= $first?>
is the same as
<?php echo $first;?>

neiljones

10:57 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



Thanks. All I needed what the header() function. I haden't seen it elsewhere. I learn best from examples and by jumping in the deep end.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month