Jump to content

Recommended Posts

New here and baffled after a lot of forum-searching (but hoping I'm overlooking something obvious nonetheless... ).

 

I have a form with some identically named checkboxes with the requisite "[]" at the end of the name (as follows in relevant part...):

 

 

<form action="/pathto/filename.php" method="post">
<p><strong>Access To:</strong><br />
Family Law Clinic <input type="checkbox" name="ctr"  value="FLC[]" checked /><br>
Pro Bono Center <input type="checkbox" name="ctr"  value="PBC[]" checked /><br>
Juvenile L. & Policy Clinic <input type="checkbox" name="ctr"  value="JLP[]" checked /><br>
Disability Law Clinic <input type="checkbox" name="ctr"  value="DLC[]"  />[/sELECT]<br>
<input name="submit" type="submit" value="Update" />
</form>

 

(The "checked" designations are there based on a database check of the user's current status, which is what this form is designed to edit.)

 

What I want and expect on the server end is an array containing any checked values submitted, which I will then implode into a single constant for the database.  What PHP yields, no matter what sort of operation I try, is a value equal to the last selected value of the four boxes.  For example:

 

if(is_array($_POST['ctr']))
{
$ctr = $_POST['ctr'];
    foreach($ctr as $value)
    {
        echo "{$value}<br />";
    }
}

else {
    echo "This is not being treated as an array: {$_POST['ctr']} ";
       }

With this coding, the "is_array" test determines the my checked values are not an array and doesn't take it through the foreach loop and the "This is not being treated as an array: {$_POST['ctr']} "; echoes with the variable as the last checked box value.

 

If I force it through the loop, I get a blank screen and the PHP warning "Invalid argument supplied for foreach() ..."

 

So it's pretty clear to me that PHP is not treating the "ctr[]" checkbox values as an array.  But I'm darned if I can figure out why not.

 

Ideas?

 

Thanks in advance, ]

 

Paul

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.