Posting values from a checkbox

I created an online schedule for my department and all works fine. I now would like to add the posibility of making an event recursive. To accomplish this, I created a small section with textboxes which will contain the days of the month:
<input type="checkbox" name="weekly" value="0">Sunday
<input type="checkbox" name="weekly" value="1">Monday
etc.
How can I correctly post the values of the selected checkboxes? I'm using PHP. Thanks!
horaliaAsked:
Who is Participating?
 
nizsmoDeveloperCommented:
Hmmm, how about something like this, it should work:

$myarray = $_REQUEST["weekly"];

foreach($myarray as $value)
{
echo $value;
// some more code here
}

This shoud work.

Let me know how you go.
0
 
nizsmoDeveloperCommented:
<input type="checkbox" name="weekly[]" value="0">Sunday
<input type="checkbox" name="weekly[]" value="1">Monday

By making the checkboxes name an Array, and then submitting the form through PHP then using foreach construct to output the array one by one with its values. Hope this is what you are looking for?

Let me know how you go.
0
 
gamebitsCommented:
First they should have different names and then you get the value like any other form input

$checkbox = $_POST['weekly'];

Keep i mind that the checkboxes who are not selected are not sent with the form data.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
horaliaAuthor Commented:
nizsmo, I used that and when posting the values, I simply got Array. I think I need to have my foreach statement modified to read Arrays. Can you give me a hand with this? Here's the code that I have to post the values coming from the edit page:

foreach($_POST as $name=>$value)
{
  if (!empty($value))
        $$name = $value;
}
foreach($_POST as $key => $value)
{
  echo "$key: $value <br>";
}
die();

When I press the submit button, this is what I get for weekly:
weekly: Array

The rest of my values are being correctly posted.
0
 
horaliaAuthor Commented:
Exactly what I needed. Thanks!
0
 
nizsmoDeveloperCommented:
Glad to be of assistance :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.