Jump to content

stuck on problem passing arrays through a form


dmikester1

Recommended Posts

I've been trying to figure this problem out for a few hours and I'm getting pretty frustrated.  I have a form with a bunch of checkboxes associated with a given athlete in a given event.  All the checkboxes are initially checked.  If any get unchecked and then the submit button is hit, it is supposed to delete the entry in the database for that athlete for that given event.  I'm to pass over an associate array containing the athlete ID connected with an event ID in a session var usin.  But I'm trying to figure out how to get a similar array passed over for the checkboxes that are or are not checked.  I can grab the athlete IDs that are associated with the checkboxes that are checked.  But I also need the event IDs to be matched up with the athlete IDs on the other side.  I've tried posting an associative relay and had no luck.  Can someone help me out?

Thanks

Mike

Link to comment
Share on other sites

As you've stated, you can only get the checked checkboxes to send data from the form.  So this is what you have:

 

  • the array of all values you used to generate the checkboxes
  • the values from the checked checkboxes when the form is submitted

 

When the form is submitted, that take the first array, loop it and remove the rows from the array based on what was checked.  This will leave you with rows that have been unchecked.

Link to comment
Share on other sites

That makes sense.  However there is still a problem.  There can be multiple checkboxes with the same value(athlete ID).  Only when you compare them against the event IDs do you get a unique instance.  So I need to get the array of checked checkboxes matched up with their associated event IDs passed over to the other side.

Thanks

Mike

Link to comment
Share on other sites

EventIDs could be unique arrays that contain values of checked athletes.

 

handler can parse those eventIDs into a single array

 

so lets say you have passed

 

Event_123[]="1,2,3,4";

Event_456[]="1,2,4";

Event_789[]="1";

 

which came from a grid of:

1 2 3 4

1 2 3 4

1 2 3 4

 

Lets assign the variable $completeGrid that value {$completeGrid=array(array(1,2,3,4),array(1,2,3,4),array(1,2,3,4))}

 

So you know that you want the unchecked array to be

[

NULL

3

2,3,4

]

 

This example is pretty simple, I don't use assoc's like I would have, but here is how I am generating the multidimensional array to compare values:

$checks=array();
foreach ($_POST as $key => $arg)
{
if (substr($key,0,6)=="Event_"){
checks[]=$arg;
}

Remember to preserve order with this example, which is why I would think it would be better to use associatives, but this can also be included as part of your POST handler. 

 

Then just do this to get the superArray:

 

superArray=array();
for ($i=0;$i<count($completeGrid);$i++){
$superArray[$i]=array_diff($completeGrid,$checks)
}

 

 

The part I'm not sure about is if the example of translating multiple single dimensional arrays into a multi-dimensional array is compatible with your current code.

Link to comment
Share on other sites

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.