Undefined index problem

Hi, i’m really stuck and would like some help…

I’ve made a simple page that will redirect a user to their desired page if they agree to a terms and conditions… the thing is, if a user doesn’t click the agree box, the page comes up but certain elements are removed from the page… the background and text formatting being the main bits…

I’ve viewed source on the page that loads once a user clicks submit without checking the box and it gives out the following error at the top of the page…

Notice: Undefined index: terms_ok in C:Program FilesEasyPHP 2.0b1wwwPopCapgame_redirect.php on line 16

If you do a refresh on this page that hasn’t loaded correctly it does indeed load the page correctly…

Obviously it’s a problem with the terms_ok checkbox but i don’t know why it is doing this??

I have played with the code a bit to remove certain information on the forum so if you paste it into a php editor the lines might be a bit messed up…

Please please please help me with this guys!

Thanks,
Andrew

[php]<?php
$terms_error = ‘’;

$selected_game = $_GET[‘game’];

$file_extension = ‘.php’;

$go_where = $selected_game.$file_extension;

if (isset($_POST[‘submitted’])) {
$valid = 1;
$terms = $_POST[‘terms_ok’];
if ( empty($terms) ) {
$valid = 0;
$terms_error = ‘Click ‘I Agree’ to proceed.’;
( $valid == 1 ) {
header(‘Location:’ .$go_where);
exit;
}
}
?>
[/php]

<HTML>
  <HEAD>
    <Link rel="stylesheet" type="text/css" href="stylesheet.css">
    <TITLE>Terms & Conditions</TITLE>
    
    
    </HEAD>

  
<BODY>
<!-- Elements Begin -->
<?php include "common_elements.html"; ?>

<!-- Terms & Conditions Begin -->        
<div class="game_holder">Terms & Conditions<br><br>

<!-- Terms Checkbox Begin -->
<form enctype="multipart/form-data" method="post" action="">

<!-- Terms Text Begin -->
<iframe width="450" height="332" src="terms.html"></iframe>
<!-- Terms Text End -->

<br>

<span style="color:#666666";>I Agree to the Terms & Conditions:</span> 

<input type="checkbox" name="terms_ok" value="agree"></input>

<span style="font-size:8pt; color:red;"><?php echo $terms_error; ?></span>
<br>

<input type="submit" name="submitted" value="Lets Go!" ></input>


</form>
<!-- Terms Checkbox End -->

</div>
<!-- Terms & Conditions End -->

        	
<!-- Ads Begin -->	
<!-- Sky -->
	<div class="skyscraper">Sky Ad</div>
    
<!-- Leaderboard -->
<div class="banner">Banner Ad<div>
<!-- Ads End -->    
	
	  
</BODY>
</HTML>

Come on, i’ve been reading around and i still can’t figure it out…

Please help me guys!

This site is great! :roll:

Doh! We’re still not working! Pain in the arse!

[php]

<?php //Pref Setup $terms_error = ''; $selected_game = $_GET['game']; $file_extension = '.php'; $go_where = $selected_game.$file_extension; $do_we_agree = 'no'; //What do we do once the user hits submit? if (isset($_POST['submitted'])) { $valid = 1; if ($_POST['terms_ok']=$do_we_agree) { $valid = 0; $terms_error = 'Please try again.'; } // If user agrees send them to their game if ( $valid == 1 ) { header('Location:' .$go_where); exit; } } ?>

[/php]

checkboxes that are not checked wound be submitted at all. neight the value nor the name. (u can see that by changing the form-methog to get)

that means that $_POST[‘terms_ok’] is always undefined when the checkbox was not checkt.

the right way to find out whether a checkbox is checked or not is: if(isset($_POST[‘cbname’]) {do something}

this may help:
[php]
if(isset($_POST[‘terms_ok’]))
{
$terms=true;
}
else
{
$terms=false;
}
[/php]

same but much shorter:
[php]$terms=isset($_POST[‘terms_ok’]);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service