Newbie question how do i echo a checkbox value to next page?
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Newbie question how do i echo a checkbox value to next p
When i ran your code i got an error Using $this when not in object context in /public_html/demo/page.php on line 7 Is this code part of anything object orientated? If not you can't use $this as a variable name as it's reserved by php
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Newbie question how do i echo a checkbox value to next p
as you may have notice i a super newbie
so what you are saying is not possible? as i dont know know what to add or remove in the code?
so what you are saying is not possible? as i dont know know what to add or remove in the code?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Newbie question how do i echo a checkbox value to next p
The sample of code below will create a form, and using your array of values create a checkbox for each item. At the moment i'm not sure what you have in mind for the script but i hope this helps get you going into the direction you wish to; The code you pasted looks as if it was part of other code and merely taken from there in the hope that it will work outside of the original script;
As you are a new php user i would advise not to use any php code that you don't understand, wrote yourself or got from an unknown 3rd party; rather paste it on the forum if you are having trouble and someone will be happy to help
As you are a new php user i would advise not to use any php code that you don't understand, wrote yourself or got from an unknown 3rd party; rather paste it on the forum if you are having trouble and someone will be happy to help
Code: Select all
<form action="" method="post">
<?php
$arr=array("hob/stove","oven","fridge/freezer","fridge","microwave","dishwasher","washing machine","tumble drye","iron/ironing board","cable tv","satellite tv","tv","telephone","internet access","central heating","air conditioning","room fans","cot","high chair","barbecue","private pool","pool heating","shared pool","pets accepted");
foreach ($arr as $value) {
echo $value . '<input type="checkbox" name="facility_id[]" value="' . $value . '" ><br />';
}
?>
<input type="submit" value="Go" name="go" />
</form>
<?php
if (isset($_POST['go'])) {
if (is_array($_POST['facility_id'])) {
foreach ($_POST['facility_id'] as $value) {
if ($value == 'air conditioning' || $value == 'private pool' || $value == 'shared pool') {
$ary[] = $value;
}
}
// comment or remove the part below this
//return $ary;
}
// loop through the array
foreach ($ary as $result) {
echo $result . '<br />';
}
}
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering