Jump to content

Value in hidden field


Ne.OnZ

Recommended Posts

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

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! :)

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.

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.