Jump to content


Simple checkbox issue

  • Please log in to reply
2 replies to this topic

#1 genista

  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 19 August 2006 - 10:13 PM

Hi all,

I want to be able to display a check box checked (if the value is checked of course) off the folowing code:

<p>Terms:</td><td><input type="checkbox" name="terms" value="<?php echo 'terms'; ?>" >

The variable is passed like so:

if (isset($_POST['terms']) == "on")
    $terms = "true";   
    $terms = "null";

What would I need to use? I am running an update users details form.



#2 Yesideez

  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 19 August 2006 - 11:02 PM

I take it you want to have a checkbox so the users can accept the terms? Try this:
<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>

Then to check if its set:
if ($_POST['subterms']) {
  if ($_POST['terms']==1) {
    echo "continue here";
  } else {
    echo "You need to accept the terms to continue";

Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#3 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 August 2006 - 11:19 PM

Here's a snippet that lets you make selections the resets those selections when the form is submitted

$interests_array = array(1 => 'Music', 'Sport', 'Computer games');

if (isset($_POST['submit'])) {
    $interests = $_POST['interest'];
else $interests = array();
<FORM method='POST'>
    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">

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users