thisisedie Posted June 27, 2009 Share Posted June 27, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/ Share on other sites More sharing options...
.josh Posted June 27, 2009 Share Posted June 27, 2009 strtolower them first Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864844 Share on other sites More sharing options...
thisisedie Posted June 27, 2009 Author Share Posted June 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864845 Share on other sites More sharing options...
.josh Posted June 27, 2009 Share Posted June 27, 2009 well in your example yellow is already lowercase so it's not like strtolower is doing anything to it. Did you apply strtolower to the user's input? Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864848 Share on other sites More sharing options...
thisisedie Posted June 27, 2009 Author Share Posted June 27, 2009 Did you apply strtolower to the user's input? *cough* how would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864850 Share on other sites More sharing options...
.josh Posted June 28, 2009 Share Posted June 28, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864872 Share on other sites More sharing options...
thisisedie Posted June 28, 2009 Author Share Posted June 28, 2009 Thanks so much for your help... but that didn't work. Maybe I didn't make it clear what I'm trying to do. I don't want the input to be case sensitive. So if the user were to type in yellow, YELLOW, or YELLow, etc, they'd all work. Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864959 Share on other sites More sharing options...
Ken2k7 Posted June 28, 2009 Share Posted June 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864961 Share on other sites More sharing options...
.josh Posted June 28, 2009 Share Posted June 28, 2009 what I posted is an example of making it case IN-sensitive. So if that didn't work then you did something wrong. Perhaps you should post your form and what you're actual code. It's case insensitive because you are making everything lowercase before comparing it. Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864962 Share on other sites More sharing options...
thisisedie Posted June 28, 2009 Author Share Posted June 28, 2009 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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864966 Share on other sites More sharing options...
Daniel0 Posted June 28, 2009 Share Posted June 28, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864970 Share on other sites More sharing options...
thisisedie Posted June 28, 2009 Author Share Posted June 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864972 Share on other sites More sharing options...
Daniel0 Posted June 28, 2009 Share Posted June 28, 2009 Change if (strlen($bots <> $badbot)) { to if (strtolower($bots) != strtolower($badbot)) { Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864973 Share on other sites More sharing options...
thisisedie Posted June 28, 2009 Author Share Posted June 28, 2009 I take it back! It worked! It worked! ;D Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864974 Share on other sites More sharing options...
thisisedie Posted June 28, 2009 Author Share Posted June 28, 2009 Thank you, thank you, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/163927-solved-how-can-i-make-this-not-case-sensitive-someone-anyone-pretty-please-o/#findComment-864975 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.