Forum Moderators: coopster
My intention is to have the days of the month listed for people to submit their availability to work
1st
2nd
3rd
etc etc
Each day will have two check boxes: Days and Nights
Every time I try to input these fields into the formmail I am using the email showing the data just shows: "Array"
Can anyone help me with what I am doing wrong?
her eis an example of the checkboxes for the first day of the month
1st: Days: <input type="checkbox" name="1st[]" value="Days"><br>
Nights: <input type="checkbox" name="1st[]" value="Nights"><br>
Something like:
foreach ($_POST['first'] as $value) {
echo 'Checkbox Set: '.$value.'<br>';
} Btw, the value of the NAME attribute should begin with a letter, not a number.
A] In the page where you have the form:
<form method="post" action="action_file.php">
<?php
for($i=1; $i<=30; $i++)
{
echo 'Day '.$i.' <input type="checkbox" name="day_'.$i.'[]" value="Days"><br />';
echo 'Night '.$i.' <input type="checkbox" name="day_'.$i.'[]" value="Nights"><br /><br />';
}
?>
<input type="submit" name="submit" value="Go" />
</form>
B] In the page the receive the form inputs:
if(isset($_POST['submit']) && $_POST['submit']=="Go")
{
for($i=1; $i<=30; $i++)
{
if(isset($_POST['day_'.$i]))
{
echo "<b>You chose day".$i.":</b> ";
foreach($_POST['day_'.$i] AS $value)
{
echo "Value: ".$value."<br />";
}
}
}
}
Hope this might help you!
Paolo
<?php
/*AFTER SUBMITTING THE FORM*/
if(isset($_POST['submit']) && $_POST['submit']=="Go")
{
for($i=1; $i<=30; $i++)
{
if(isset($_POST['day_'.$i]))
{
echo "<b>You chose day".$i.":</b> ";
foreach($_POST['day_'.$i] AS $value)
{
echo "Value: ".$value."<br />";
}
}
}
die();
}
?>
<!-- ACTUAL FORM-->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
for($i=1; $i<=30; $i++)
{
echo 'Day '.$i.' <input type="checkbox" name="day_'.$i.'[]" value="Days"><br />';
echo 'Night '.$i.' <input type="checkbox" name="day_'.$i.'[]" value="Nights"><br /><br />';
}
?>
<input type="submit" name="submit" value="Go" />
</form>
2] Launch it and check, for instance, night for the 28th, day for the 29th, and both day and night for the 30th. Submit the form; you should get this:
You chose day28: Value: Nights
You chose day29: Value: Days
You chose day30: Value: Days
Value: Nights
If you can see this...it's good starting point! In my opinion your mistake is that you don't step through the array, like I do when I write
foreach($_POST['day_'.$i] AS $value)
{
echo "Value: ".$value."<br />";
}
Paolo
-Open a new php file with your favourite text-editor and copy the entire code I posted.
-Save such a file (i.e. my-form.php) in your local server directory (which should be /htdocs if you're using apache)
-Launch it in your browser (http://localhost/my-form.php)
-Check randomly some values and then submit the form by clicking on the button at the very bottom of the page
-See what you get...
What I was trying to tell you in my previous post is that if you have a variable (i.e. $my_var) which is an array, if you say echo $my_var you'll see "Array", which is not exactly what you're aiming to do. To be able to see the values stored in the array you have to step through it by using, for instance, the "foreach" statement.
So, if you have
$my_var=array('key1'=>'value1', 'key2'=>'value2');
if you just echo $my_var you'll see "Array" on your screen but if you:
foreach ($my_var AS $val)
{
echo $val."<br />";
}
you'll get:
value1
value2
that's the actual values stored in the array.
Hope to have been more exhaustive than before ;-)
Paolo
-Open a new php file with your favourite text-editor and copy the entire code I posted.
-Save such a file (i.e. my-form.php) in your local server directory (which should be /htdocs if you're using apache)
-Launch it in your browser (http://localhost/my-form.php)
-Check randomly some values and then submit the form by clicking on the button at the very bottom of the page
-See what you get...
What I was trying to tell you in my previous post is that if you have a variable (i.e. $my_var) which is an array, if you say echo $my_var you'll see "Array", which is not exactly what you're aiming to do. To be able to see the values stored in the array you have to step through it by using, for instance, the "foreach" statement.
So, if you have
$my_var=array('key1'=>'value1', 'key2'=>'value2');
if you just echo $my_var you'll see "Array" on your screen but if you:
foreach ($my_var AS $val)
{
echo $val."<br />";
}
you'll get:
value1
value2
that's the actual values stored in the array.
Hope to have been more exhaustive than before ;-)
Paolo