...

View Full Version : Disallowing certain domains in a form



Errica
11-28-2005, 03:24 PM
<input name="EmailOne" type="text" size="32" maxlength="150">

How can I disallow two domains (ie. @domain1.com and @domain2.com) in the above?

mark87
11-28-2005, 03:50 PM
You'd need to use a server side language. What processes it at the moment? A PHP script or?

Errica
11-28-2005, 03:53 PM
It's currently a perl script but I can use php

mark87
11-28-2005, 04:10 PM
I don't know Perl but I found this -

http://www.tigertom.com/perl-script.shtml

The 'Fraud Filter' script seems to say it could do what you want. It can currently ban free email addresses so I'm sure you could edit the script to disallow the ones you don't want.

whizard
11-28-2005, 08:22 PM
You could also set up your form so that it would be like this:

[textbox for address]@[textbox for domain]

then you could validate the second box:



if($_POST['email_domain'] == [array of bad domains])
{
?>
<script type="text/javascript">
alert("This domain is not allowed. Please enter a legal domain.");
history.go(-1);
</script>
<?php
}


I dont recommend this over a method where you could enter the email all in one box, but it would work

Sincerely
Dan

Errica
11-28-2005, 08:30 PM
You could also set up your form so that it would be like this:

[textbox for address]@[textbox for domain]

then you could validate the second box:



if($_POST['email_domain'] == [array of bad domains])
{
?>
<script type="text/javascript">
alert("This domain is not allowed. Please enter a legal domain.");
history.go(-1);
</script>
<?php
}


I dont recommend this over a method where you could enter the email all in one box, but it would work

Sincerely
Dan

Good idea, I'll try this. I'm having a problem with someone using a form on our site to send spam.

Bill Posters
11-28-2005, 11:37 PM
belts and braces…
i.e. client-side (js) + server-side (php)…

e.g.

test.php

<?php

$badDomains = array('domain1.com','domain2.com');

if (isset($_POST['email'])) {

$emailArray = explode('@',$_POST['email']);
$emailDomain = $emailArray[1];

if (in_array($emailDomain, $badDomains)) {
$msg = 'Blocked domain' ; /* do something bad */
} else {
/* do something good */
}

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>test</title>
<script type="text/javascript">

var badDomains = new Array('domain1.com','domain2.com');

function in_array() {

var userEmailDomain = document.getElementById('email').value.split('@')[1];
var badDomainsStr = badDomains.toString();

if (badDomainsStr.indexOf(userEmailDomain) != -1) {
alert('Blocked domain'); return false;
}

}

/* OR */

function in_array() {

var userEmailDomain = document.getElementById('email').value.split('@')[1];

var n = badDomains.length;
for (var i=0; i<n; i++) {
if (badDomains[i] == userEmailDomain) {
alert('Blocked domain'); return false;
}
}

}

</script>
</head>
<body>

<form action="<?php echo $_SERVER['PHP_SELF'] ; ?>" method="post" onsubmit="return in_array();">
<fieldset>

<input type="text" id="email" name="email" /><br />
<input type="submit" value="submit" />

</fieldset>
</form>

<p><?php if (isset($msg)) echo $emailDomain." = ".$msg ; ?></p>

</body>
</html>

There are two js options in there for checking for the presence of the email domain in the array of blocked domains.

You may wish to additionally perform some regEx on the input value to check that it's a valid email syntax before accepting it, mainly for the sake of non-blocked email domains.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum