Jump to content

[SOLVED] How Can I Make This Not Case Sensitive? Someone... ANYONE? Pretty Please :o)


thisisedie

Recommended Posts

Hi there. I've been using a simple mail form which I found online ages ago and modified to death. Now I'm trying to add a verification (my own creation -- to get rid of the spam I'm suddenly getting) which works great except it insists on being case sensitive.

 

Ok so (sorry I'm not very technical) -- at the top I have: $badbot = yellow;

 

Below the textarea box I have a picture of bananas that asks what color bananas are.

 

In the area that defines the errors I have:

 

if (strlen($bots <> $badbot)) {

$error = true;

$error4 = errorBots;

}

 

The results are that if someone types in "yellow" it works fine but "YELLOW" or yElloW", etc throws up the error. Any help would be greatly appreciated!

Link to comment
Share on other sites

I was looking at the earlier and couldn't make it work. I tried:

 

$badbot = "yellow";

$badbot = strtolower($badbot);

echo $badbot;

 

I'd like to note that I know this is probably simple and the reason I'm clueless is because I haven't done much PHP programming (or any other kind for that matter). Mostly I've just dabbled  :)

Link to comment
Share on other sites

Okay for example, if the input field in the form is named "answer" :

 

<?php
  $answer = "yellow"; // this is the answer you are comparing to the user's input
  if (strtolower($_POST['answer']) == $answer) {
    // case insensitive match!
  } else {
    // error stuff here
  }
?>

Link to comment
Share on other sites

You're so not getting the logic.

 

The if statement should read something like this -

 

if (strtolower($user_input) === strtolower($bot))

 

If you use strtolower for both the user input and the variable, then both will be lowercased for the if conditional.

Link to comment
Share on other sites

Heh Ken I'm really NOT getting it. As I said, I don't have much experience with PHP. CSS is another story. I'm the CSS Queen! Thanks for your patience guys  :)

 

I've tried making your suggestions work with my code and can't figure it out so I guess I'll go ahead and post the entire code. Thanks again  :)

 

<?php
define("MAIL_TARGET","");
define("errorcName","<span class=\"star\">♦</span> Please enter your name.<br/>");
define("errorEmail","<span class=\"star\">♦</span> Please enter a valid email address.<br/>");
define("errorMsg","<span class=\"star\">♦</span> Please type a message.<br/>");
define("errorBots","<span class=\"star\">♦</span> Please answer the banana question.");
$badbot = yellow;

function createForm($cname="",$email="",$url="",$message="",$bots="",$error1="",$error2="",$error3="",$error4=""){
?>
<p><span class="stitle">CONTACT</span><br/>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/sl.png" width="195" height="6" alt=""/><br/>
Send me a private message using the form below.</p>

<p class="tmess">
<?php echo $error1; ?>
<?php echo $error2; ?>
<?php echo $error3; ?>
<?php echo $error4; ?></p>

<div class="sformalign">
<form action="" method="post">
<input type="text" name="cname" style="width:195px; text-align:center;" value="<?php echo $cname; ?>" class="formsname"/><br/>
<div class="betff"></div>
<input type="text" name="email" style="width:195px; text-align:center;" value="<?php echo $email; ?>" class="formsemail"/><br/>
<div class="betff"></div>
<input type="text" name="url" style="width:195px; text-align:center;" value="<?php echo $url; ?>" class="formsurl"/><br/>
<div class="betff"></div>
<textarea name="message" cols="10" rows="5" class="formsmessage"><?php echo $message; ?></textarea><br/>
<div class="betff"></div>
<div><img src="/images/bots.png" width="100" height="75" style="float:left;" alt=""/><div style="padding-top:25px;"><input type="text" name="bots" value="<?php echo $bots; ?>" class="formsbots"/><br/><input name="submitBtn" type="submit" value="SEND" class="ssubm"/></div></div>
</form></div>

<?php
}
function isValidEmail($email){
$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
if (eregi($pattern, $email)){
return true;
}
else {
return false;
}
}
function sendMail($cname,$email,$url,$message){
$ipi = $_SERVER["REMOTE_ADDR"];
$httpagenti =  $_SERVER["HTTP_USER_AGENT"];
$subject = "Message From DC";
$from = "From: $cname <$email>\r\nReply-To: $email\r\n"; 
$header  = "MIME-Version: 1.0\r\n"."Content-type: text/html; charset=iso-8859-1\r\n";
$message = stripslashes(nl2br($message));
$content = htmlspecialchars($message);
$content = wordwrap($content,70);
$content = "$url<br/><br/>$message<br/><br/>$ipi<br/>$httpagenti";
mail(MAIL_TARGET,$subject,$content,$from.$header);
}
?>
<?php if (!isset($_POST['submitBtn']))  { 
createForm();
} else  { 
$cname = isset($_POST['cname']) ? $_POST['cname'] : "";
$email= isset($_POST['email']) ? $_POST['email'] : "";
$url= isset($_POST['url']) ? $_POST['url'] : "";
$message = isset($_POST['message']) ? $_POST['message'] : "";
$bots = isset($_POST['bots']) ? $_POST['bots'] : "";

$error  = false;
$error1 = '';
$error2 = '';
$error3 = '';
$error4 = '';

if (strlen($cname)<1) {
$error = false;
$error1 = errorcName;
}
if (!isValidEmail($email)) {
$error = true;
$error2 = errorEmail;
}
if (strlen($message)<1) {
$error = true;
$error3 = errorMsg;
}
if (strlen($bots <> $badbot)) {
$error = true;
$error4 = errorBots;
}

if ($error){
createForm($cname,$email,$url,$message,$bots,$error1,$error2,$error3,$error4); 
}
else {
sendMail($cname,$email,$url,$message);
?>
<p><span class="stitle">CONTACT</span><br/>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/sl.png" width="195" height="6" alt=""/><br/>
Send me a private message using the form below.</p>

<p class="tmess">Thanks for sending me a message!</p>

<div class="sformalign">
<form action="" method="post">
<input type="text" name="cname" style="width:195px; text-align:center;" value="" class="formsname"/><br/>
<div class="betff"></div>
<input type="text" name="email" style="width:195px; text-align:center;" value="" class="formsemail"/><br/>
<div class="betff"></div>
<input type="text" name="url" style="width:195px; text-align:center;" value="" class="formsurl"/><br/>
<div class="betff"></div>
<textarea name="message" cols="10" rows="5" class="formsmessage"></textarea><br/>
<div class="betff"></div>
<div><img src="/images/bots.png" width="100" height="75" style="float:left;" alt=""/><div style="padding-top:25px;"><input type="text" name="bots" value="" class="formsbots"/><br/><input name="submitBtn" type="submit" value="SEND" class="ssubm"/></div></div>
</form></div>
<?php
}
}
?>

Link to comment
Share on other sites

If you want case-insensitivity, make both of them lower case (or uppercase, it doesn't matter). 'Foo' != 'foo', but because strtolower('Foo') == 'foo', strtolower('Foo') == 'foo', but also strtolower('FOO') == 'foo' and strtolower('foO') == 'foo' and so on. Get it? :)

Link to comment
Share on other sites

Yep I get it... I just don't understand how to implement it because apparently I'm a big ole PHP dummy LOL. Either that or I'm too tired to think. So I'm just gonna give up for now and tag a little note telling users to type in lowercase. Sigh. Thanks so much for all your help  ;D

Link to comment
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.