genista Posted August 19, 2006 Share Posted August 19, 2006 Hi all,I want to be able to display a check box checked (if the value is checked of course) off the folowing code:[code=php:0]<p>Terms:</td><td><input type="checkbox" name="terms" value="<?php echo 'terms'; ?>" >[/code]The variable is passed like so:[code=php:0]if (isset($_POST['terms']) == "on") $terms = "true"; $terms = "null";[/code]What would I need to use? I am running an update users details form.Thanks,G Link to comment https://forums.phpfreaks.com/topic/18058-simple-checkbox-issue/ Share on other sites More sharing options...
Yesideez Posted August 19, 2006 Share Posted August 19, 2006 I take it you want to have a checkbox so the users can accept the terms? Try this:[code]<tr><td>Terms</td><td><?=$terms?></td></tr><tr><td colspan="2"><input type="checkbox" name="terms" value="1"> Accept the terms</td></tr><tr><td colspan="2"><input type="submit" name="subterms" value="Continue"></td></tr>[/code]Then to check if its set:[code]if ($_POST['subterms']) { if ($_POST['terms']==1) { echo "continue here"; } else { echo "You need to accept the terms to continue"; }}[/code] Link to comment https://forums.phpfreaks.com/topic/18058-simple-checkbox-issue/#findComment-77390 Share on other sites More sharing options...
Barand Posted August 19, 2006 Share Posted August 19, 2006 Here's a snippet that lets you make selections the resets those selections when the form is submitted[code]<?php$interests_array = array(1 => 'Music', 'Sport', 'Computer games');if (isset($_POST['submit'])) { $interests = $_POST['interest'];}else $interests = array();?><FORM method='POST'><p>Interests</p><?php foreach ($interests_array as $k => $int) { $chk = in_array($k, $interests) ? 'checked' : ''; echo "<input type='checkbox'' name='interest[]'' value='$k' $chk> $int<br>" ; }?><input type="submit" name="submit" value="Submit"></FORM> [/code] Link to comment https://forums.phpfreaks.com/topic/18058-simple-checkbox-issue/#findComment-77397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.