homepage Welcome to WebmasterWorld Guest from 54.161.247.22
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Newbie question on php validation
is action="<?php echo $PHP_SELF?>"> the way?
neiljones




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

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




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

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




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved