NoSalt Posted November 26, 2008 Share Posted November 26, 2008 Hello All I am working on a project and I could use some advice. I have a site that people can join. They enter an email address and password. Right now I am using javascript to check the form of the email address to make sure that it is a valid "looking" email. What I am looking for is a PHP way to do this. I already have the following successfully working: <?php $email = (isset($_POST['email'])) ? $_POST['email'] : null; $password = (isset($_POST['password'])) ? $_POST['password'] : null; $emailFilter = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/'; if(preg_match($emailFilter, $email)){ header("Location: ./index.php?msg=success"); exit; } else{ header("Location: ./index.php?msg=failure"); exit; } ?> The thing that JavaScript will let me do is to keep all of the already correctly populated fields still populated, so that the user doesn't have to fill in the form all over again. I know I can pass the POSTed values back in the URL but if it's a password I don't really want to do that. Any suggestions??? Thanks for reading Quote Link to comment https://forums.phpfreaks.com/topic/134304-advice-needed/ Share on other sites More sharing options...
Philip Posted November 26, 2008 Share Posted November 26, 2008 If you have the form on the same page, you can do it like: <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <input type="text" name="email" value="<?php if(isset($_POST['email'])) { echo $_POST['email']; }?>"> ... </form> If not, then you could do sessions (i wouldnt recommend it since it takes up some memory for something pretty trivial such as this), or via GET & passing it through the URL. I would suggest looking into integrating the form on the same page as the php script. Quote Link to comment https://forums.phpfreaks.com/topic/134304-advice-needed/#findComment-699218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.