Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Passing Checkboxes in PHP?
I am trying to pass a form in PHP between pages using $_POST. I'm getting snagged up on the check boxes. I've tried a few things here's my latest attempt...
The error is... Notice: Undefined index: field_trip
Here's some code.
On the form page... <input type="checkbox" name="field_trip[]" id="field_trip[]" value="saline" />
On the next page... I've tried...
$trip = $_POST['field_trip'];
Also...
if(isset($_POST['field_trip'])...
{ echo "stuff";}
Also..
if($_POST['field_trip'] != "")
{do stuff}
None of it seems to work. I've also used field_trip[] on the second page to no avail.
Help please.
5 Answers
- 1 decade agoFavorite Answer
It is clear that field trip is an array. so its an obvious that above code will not work.
You should do following
$trip = $_POST['field_trip']; // this is ok
foreach($trip as $mytrip)
{
// do whatever you like here
echo $mytrip;
}
alternatives
$trip = $_POST['field_trip']; // this is ok
for($i=0;$i<count($trip);$i++)
{
// do whatever you like here
echo $trip[$i];
}
Note that trip is an array.
- 1 decade ago
When you submit to a php page you can read your variable like this:
$checkBoxArray = $_POST['field_trip'];
And you can now browser through this post variable using $checkBoxArray variable.
try this to see what variables are actually being posted
print "<pre>"
print_r ($_REQUEST);
This will show you all your get/post variables available.
- 1 decade ago
Try this - replace VALUE with your checked value.
<?php if ($_POST['field_trip'] == VALUE) {echo 'Blah Blah';} ?>
- 1 decade ago
I notice on your form code the name of your check box is name="field_trip[]"
remove the [] or [ ]
just name it like this name="field_trip"
it should work :-)
- How do you think about the answers? You can sign in to vote the answer.
- immanuelLv 44 years ago
internet site a million: <enter kind="checkbox" call="field_trip[]" fee="value1">fee a million <enter kind="checkbox" call="field_trip[]" fee="value2">fee 2 <enter kind="checkbox" call="field_trip[]" fee="value3">fee 3 internet site 2: $field_trip = $placed up['field_trip']; foreach ($field_trip as $fee) { # artwork here }