Ne.OnZ Posted May 22, 2008 Share Posted May 22, 2008 Hello, I can't seem to set a value in a hidden input field. Here's what I have: $security = $_POST['bot']; $bot = $_POST['bot2']; for($i = 0; $i<10; $i++) { $temp = rand(0, 9); if($temp == 1) { echo "<img src='images/Code/1.png' alt='' />"; } else if($temp == 2) { echo "<img src='images/Code/2.png' alt='' />"; } else if($temp == 3) { echo "<img src='images/Code/3.png' alt='' />"; } else if($temp == 4) { echo "<img src='images/Code/4.png' alt='' />"; } else if($temp == 5) { echo "<img src='images/Code/5.png' alt='' />"; } else if($temp == 6) { echo "<img src='images/Code/6.png' alt='' />"; } else if($temp == 7) { echo "<img src='images/Code/7.png' alt='' />"; } else if($temp == { echo "<img src='images/Code/8.png' alt='' />"; } else if($temp == 9) { echo "<img src='images/Code/9.png' alt='' />"; } else if($temp == 0) { echo "<img src='images/Code/0.png' alt='' />"; } $code = "{$code}{$temp}"; } echo "<br />Security Code: <input type='text' id='bot' name='bot' tabindex='9' class='regs' /> <input type='hidden' id='bot2' name='bot2' /> After you hit submit, I have this to check for it: if($security != $bot) { echo "<p>The Security code you entered is invalid.</p> $security" . '<br />$bot'; $set = 1; } For debugging purposes, I echoed $security and $bot to see if they had any values. It appeared when I echo $bot, it only prints "$bot". So I'm guessing it's not getting set in there. Any ideas to what may be wrong? Thank You! Link to comment https://forums.phpfreaks.com/topic/106784-value-in-hidden-field/ Share on other sites More sharing options...
rhodesa Posted May 22, 2008 Share Posted May 22, 2008 First, in your HTML, I don't see you setting the value. But in your second block of code, it prints $bot because variables aren't evaluated inside single quotes. Use double quotes instead. Link to comment https://forums.phpfreaks.com/topic/106784-value-in-hidden-field/#findComment-547389 Share on other sites More sharing options...
Ne.OnZ Posted May 22, 2008 Author Share Posted May 22, 2008 Thank you for mentioning the information about the double quotes. It appeared that "8.png" had the image of 9. It works perfectly now. Thank You! Link to comment https://forums.phpfreaks.com/topic/106784-value-in-hidden-field/#findComment-547404 Share on other sites More sharing options...
Ne.OnZ Posted May 22, 2008 Author Share Posted May 22, 2008 Woah, I just noticed what you meant by setting the value. It is true I never set the value to $bot. So how is $code being sent to $bot. o.O Wierd Link to comment https://forums.phpfreaks.com/topic/106784-value-in-hidden-field/#findComment-547410 Share on other sites More sharing options...
Ne.OnZ Posted May 22, 2008 Author Share Posted May 22, 2008 WOuldn't let me edit above post........but it stopped working again x.X Probably because I didn't set the variable $code to bot2. Ok, I'm pretty much lost now. If I put $code = $_POST['bot2']; It echoes nothing when you hit submit. So the value is not being sent to the hidden field. If I use a different value, how would I set that variable to equal $code and then set it to $_POST['bot2']. Thank You! Link to comment https://forums.phpfreaks.com/topic/106784-value-in-hidden-field/#findComment-547418 Share on other sites More sharing options...
rhodesa Posted May 22, 2008 Share Posted May 22, 2008 I just realized...are you trying to make a CAPTCHA to prevent spammers? Cus this is a bad way of doing it. There are lots of CAPTCHA scripts out there that will work MUCH better. Also, if this is for something basic, like a contact form, I would use something like this: http://www.modernblue.com/web-design-blog/fighting-spam-with-css/ It works 99% of the time, and is transparent to real users. Link to comment https://forums.phpfreaks.com/topic/106784-value-in-hidden-field/#findComment-547444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.