SirChick Posted September 28, 2007 Share Posted September 28, 2007 My code won't allow the validation to succeed if everything is ok. I have a check box which the user has to tick in order for the process to take place. I'm not sure why but it always dies and produces my error . Form : <form name="" method="POST" action="breakoutofjail.php" enctype="text/plain" id="Form1"> <div id="bv_Text2" style="position:absolute;left:158px;top:92px;width:150px;height:16px;z-index:1" align="center"> <font style="font-size:13px" color="#000000" face="Arial"><i>Costs 10 Courage!</i></font></div> <input type="checkbox" id="Checkbox1" name="BreakOutCheckBox" value="" style="position:absolute;left:324px;top:58px;z-index:2"> <input type="submit" id="Button1" name="BreakOut" value="Try To Break Out" style="position:absolute;left:158px;top:57px;width:144px;height:24px;z-index:0"> </form> This is the validation on the breakoutofjail.php : $Check = $_POST['BreakOutCheckBox']; $Check = (isset($_POST['BreakOutCheckBox']) ? true : false); if (!$Check) { die("You must tick the validation box, this avoids people accidently clicking the button!"); } If i echo $Check there is no response to it so its completely empty... even when ticked or not. Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/ Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 Give the value of BreakOutCheckBox "yes" value="yes" Then when it comes to the PHP part try: $Check = $_POST['BreakOutCheckBox']; if($check == "yes"){ echo "Validated"; }else { echo "Invalidated"; } Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357246 Share on other sites More sharing options...
SirChick Posted September 28, 2007 Author Share Posted September 28, 2007 This is the new alteration but still not working. <input type="checkbox" id="Checkbox1" name="BreakOutCheckBox" value="yes" style="position:absolute;left:324px;top:58px;z-index:2"> $Check = $_POST['BreakOutCheckBox']; if (!($Check == 'Yes')){ die("You must tick the validation box, this avoids people accidently clicking the button!"); } Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357265 Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 your value is equal to "yes" not "Yes" Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357272 Share on other sites More sharing options...
SirChick Posted September 28, 2007 Author Share Posted September 28, 2007 Oops.. just changed but still wont work . Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357280 Share on other sites More sharing options...
Psycho Posted September 28, 2007 Share Posted September 28, 2007 Two things: There is nothing technically wrong with your IF statement, but I would suggest changing it to this: if ($Check != 'Yes'){ Let's verify that the receiving page is getting the values you are expecting. Put this on the page receiving the post data. print_r($_POST); Please post the output. Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357288 Share on other sites More sharing options...
SirChick Posted September 28, 2007 Author Share Posted September 28, 2007 Array ( ) Thats all it says. Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357290 Share on other sites More sharing options...
Psycho Posted September 28, 2007 Share Posted September 28, 2007 Then your data is not getting posted! Please show the FORM on your page. Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357307 Share on other sites More sharing options...
SirChick Posted September 28, 2007 Author Share Posted September 28, 2007 <? include ("jailinclude.php"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>British Jail</title> </head> <body bgcolor="#FFAD5B" text="#000000" style="scrollbar-face-color:#C8E8F8;scrollbar-arrow-color:#000000;scrollbar-3dlight-color:#C8E8F8;scrollbar-darkshadow-color:#404040;scrollbar-highlight-color:#E8F4FF;scrollbar-shadow-color:#40B0E8;scrollbar-track-color:#E8F4FF;"> <div id="bv_" style="position:absolute;left:233px;top:290px;width:430px;height:32px;z-index:3" align="center"> <font style="font-size:13px" color="#000000" face="Arial"><b>You are in jail! You must wait till you are released before you can continue your normal Civilian Life!</b></font></div> <div id="bv_" style="position:absolute;left:294px;top:193px;width:280px;height:16px;z-index:4" align="left"> <font style="font-size:13px" color="#000000" face="Arial"><u>Time In Jail:</u> <b><?= $TimeInJail ?> minutes.</b></font></div> <img src="Banner1.jpg" id="Image1" alt="" align="top" border="2" width="996" height="96" style="position:absolute;left:0px;top:0px;width:996px;height:96px;border-color:#FFFFFF;z-index:5"> <div id="bv_" style="position:absolute;left:216px;top:366px;width:472px;height:150px;z-index:6" align="left"> <form name="" method="POST" action="breakoutofjail.php" enctype="text/plain" id="Form1"> <div id="bv_Text2" style="position:absolute;left:158px;top:92px;width:150px;height:16px;z-index:1" align="center"> <font style="font-size:13px" color="#000000" face="Arial"><i>Costs 10 Courage!</i></font></div> <input type="checkbox" id="Checkbox1" name="BreakOutCheckBox" value="Yes" style="position:absolute;left:324px;top:58px;z-index:2"> <input type="submit" id="Button1" name="BreakOut" value="Try To Break Out" style="position:absolute;left:158px;top:57px;width:144px;height:24px;z-index:0"> </form> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357309 Share on other sites More sharing options...
Psycho Posted September 28, 2007 Share Posted September 28, 2007 Remove the enctype property from the FORM tag. You only need that when doing file uploads. And you should know the valid values for that property and what they mean before using them. Link to comment https://forums.phpfreaks.com/topic/71046-check-box-validation/#findComment-357463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.