iarp Posted November 22, 2008 Share Posted November 22, 2008 I thought this was going to be a simple form to change a cookies value, but i can't figure out wtf is wrong. I'm in need of assistance please. <?php require_once('MDS_includes/header.php'); if(isset($_POST['submitted'])) { $temp = $_POST['links']; $t = $temp; $expire = time()+60*60*24*30; setcookie("mds_viewtype", $t, $expire); } ?> <form action="prefs.php" method="post"> <label>How would you like product links to open?</label><br /> <input type="radio" name="links" value="1" id="501" <?php if ($_COOKIE['mds_viewtype'] == '1') echo checked; ?> /><label for="501">Not in a popup maner</label><br /> <input type="radio" name="links" value="2" id="502" <?php if ($_COOKIE['mds_viewtype'] == '2') echo checked; ?> /><label for="502">With javascript popups(default)</label><br /> <input type="submit" name="submit" value="Submit" /> <input type="hidden" value="submitted" name="submitted"/> </form> <?php require_once('MDS_includes/footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133745-solved-cookies-problem/ Share on other sites More sharing options...
.josh Posted November 22, 2008 Share Posted November 22, 2008 You can start by telling us what the problem is and if there are any errors. Quote Link to comment https://forums.phpfreaks.com/topic/133745-solved-cookies-problem/#findComment-696017 Share on other sites More sharing options...
rhodesa Posted November 22, 2008 Share Posted November 22, 2008 close...but a couple things.. #1 When you use setcookie, the value in $_COOKIE isn't available until the NEXT page load. To get around this, after you set the cookie, send the page back to itself with header(). It won't run recursively, cus when you send it back to itself, it will loose the POST #2 echo checked is missing quotes around 'checked'. and, to be picky, it should be checked=true <?php require_once('MDS_includes/header.php'); if(isset($_POST['submitted'])) { $temp = $_POST['links']; $t = $temp; $expire = time()+60*60*24*30; setcookie("mds_viewtype", $t, $expire); header('Location: '.$_SERVER['PHP_SELF']); exit; } ?> <form action="" method="post"> <label>How would you like product links to open?</label><br /> <input type="radio" name="links" value="1" id="501" <?php if ($_COOKIE['mds_viewtype'] == '1') echo 'checked="true"'; ?> /><label for="501">Not in a popup maner</label><br /> <input type="radio" name="links" value="2" id="502" <?php if ($_COOKIE['mds_viewtype'] == '2') echo 'checked="true"'; ?> /><label for="502">With javascript popups(default)</label><br /> <input type="submit" name="submit" value="Submit" /> <input type="hidden" value="submitted" name="submitted"/> </form> <?php require_once('MDS_includes/footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133745-solved-cookies-problem/#findComment-696019 Share on other sites More sharing options...
iarp Posted November 22, 2008 Author Share Posted November 22, 2008 Works like a dream, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/133745-solved-cookies-problem/#findComment-696025 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.