Jump to content

Only allow email addresses to be submitted


dachshund

Recommended Posts

Hi there,

 

I have a newsletter sign up form which just puts the data (id and email) into a mysql table.

 

To stop people hacking the site, is there a way to make sure the only thing being submitted in the input is an email address?

 

Here's my current form and submit php:

 

<?php

$mailer = $_GET['mailer'];

if ($mailer == 'added')	{

$email=$_POST['email'];

if($email == '')	{
echo '<div class="daily_not_submitted"><span style="padding-right:6px;"><img src="https://store.huhmagazine.co.uk/images/cross.jpg"></span>Please fill in all the fields.</div>';
}else	{

$sql="INSERT INTO `dailymailer` (`email`) VALUES ('$email');";
$result=mysql_query($sql) or die(mysql_error());

if($result){
echo "<div class='daily_submitted'><span style='padding-right:6px;'><img src='http://www.huhmagazine.co.uk/images/uploaded/checkboxtick.jpg'></span>Thank you.</div>";
}
else {
echo "Error\n";
}
}
}
?>

<div id="sidebarnewsletter">
	<form name="mailinglist" method="post" action="?mailer=added">
		<input type="text" name="email" class="sidebarnewsletter" placeholder="Enter Your Email Address" />
		<input type="submit" class="sidebarnewsletter_button" value="Sign Up">
	</form>
	<div class="clear"></div>
</div>

Hello,

 

You could always start with checking to see whether they have included the "@" character in the post via..

 

<?php

    // If they dont have the "@" character..
    if(!strstr($_POST['userEmail'], '@')){

        // Do something.

    }

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.