Jump to content

Archived

This topic is now archived and is closed to further replies.

genista

Simple checkbox issue

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

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.