Jump to content

Simple checkbox issue


genista

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.