Jump to content

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/134304-advice-needed/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/134304-advice-needed/#findComment-699218
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.