/    Sign up×
Community /Pin to ProfileBookmark

Checked checkbox

Hi!

I try to control the checkbox so it’s checked or unchecked when the form start, but I get an error al the time.

Couldn’t $checkboxStatus be ‘checked’ or ” ?

$form = <<< EOD
<form id=’hangman’ action=’hangman.php’ method=’get’>
Debug on/off <input type=’checkbox’ name=’debugControl’ value='{$debugControl}’ {$checkboxStatus} />
<button type=’submit’>Gissa</button>
</form>
EOD;

Preciate some help!

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@pavsidOct 10.2009 — Hi!

I try to control the checkbox so it's checked or unchecked when the form start, but I get an error al the time.

Couldn't $checkboxStatus be 'checked' or '' ?

$form = <<< EOD

<form id='hangman' action='hangman.php' method='get'>

Debug on/off <input type='checkbox' name='debugControl' value='{$debugControl}' {$checkboxStatus} />

<button type='submit'>Gissa</button>

</form>

EOD;

Preciate some help![/QUOTE]


Hi pkng, your code works fine for me, what error are you getting? make sure you have no characters (even spaces) after '<<< EOD' and nothing before 'EOD;' (should be fully to the left)
Copy linkTweet thisAlerts:
@pkngauthorOct 10.2009 — Thanks!

I'm getting some XML error since I have header in the end of the php file

header("Content-Type: application/xhtml+xml; charset=iso-8859-1");

echo $html;

exit;

but if I write like this: $checkboxStatus = "checked='checked'"; then it looks like it works?! But I want to do it as simple as possible?
Copy linkTweet thisAlerts:
@pavsidOct 10.2009 — The problem is with your content-type, if you replace application/xhtml+xml with text/html then it'll work fine, but perhaps this isn't what you want...

what are you trying to do?
Copy linkTweet thisAlerts:
@pkngauthorOct 10.2009 — Thanks! No I can't change to text/html then I get a lot of other problems because there is a lot of classes and so on with SVG images that I don't know so much about yet. This is a task that I'm going to hand in tomorrow.

What I want to do is have a checkbox checked or unchecked from the beginning by a $variable and when I press the submit button, I want the checkbox to still be checked.

Due to if the checkbox is checked or unchecked I want to activate some code.

So, I'm also trying to create som code that check the status of the value in the checkbox? I only have on like on/off.

Hopefully this is clear how I'm trying to do?!
Copy linkTweet thisAlerts:
@MindzaiOct 10.2009 — For compliant XHTML you can't have single attributes such as "checked". You need to use the checked="checked" format. I usually do something like this:

[code=php]
<?php $checked = $condition == true ? ' checked="checked"' : null ?>
<input type="checkbox" name="foo" value="1"<?php echo $checked ?>/>
[/code]
Copy linkTweet thisAlerts:
@pavsidOct 10.2009 — For compliant XHTML you can't have single attributes such as "checked". You need to use the checked="checked" format.[/QUOTE]

The error he's getting is

[CODE]XML Parsing Error: no element found
Location: http://example.com/path/to/file.php
Line Number 1, Column 1:[/CODE]


Although the XHTML might not validate, i don't think that's the issue right now.

I would suspect the content-type declaration (application/xhtml+xml) - i know little about this so can't really help any further unfortunately. Sure someone else will though
Copy linkTweet thisAlerts:
@MindzaiOct 10.2009 — Changing the content type declaration is like cutting off a leg to fix a broken toe. It might work, but it's not addressing the issue.

@OP - can you post the entire output of the script which is giving the error?
Copy linkTweet thisAlerts:
@pavsidOct 10.2009 — Changing the content type declaration is like cutting off a leg to fix a broken toe. It might work, but it's not addressing the issue.

@OP - can you post the entire output of the script which is giving the error?[/QUOTE]


I'm not saying change it, just make sure it's being used correctly
×

Success!

Help @pkng spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...