Jump to content

Post an array of checkboxes


aeboi80

Recommended Posts

So basically I have a script which the user can import a list of email addresses from their address book.  When the user imports the list of emails it shows them on the screen as a series of checkboxes and places them in an array $contacts->email_array[$key];

 

<input name="chk_email[]" type="checkbox" id="members2" value="<?php echo $contacts->email_array[$key]; ?>" checked >

 

[x] [email protected]

[x] [email protected]

[x] [email protected]

 

etc....

 

The user can uncheck any addresses which they ultimately do not want to send an invitation to.

When the user unchecks the check box it is removed from the array $contacts->email_array[$key];

 

 

Once the user has checked which email address they want to send an invite to they will click a button on form2 which will direct them to the page where they actually compose the email they want to send.

 

What I need to be able to do is take this array: $contacts->email_array[$key]; and post the array to $_POST so I can access it on the createemail.php page

 

I just don't know how to go about it.

 

Chad

Link to comment
https://forums.phpfreaks.com/topic/198037-post-an-array-of-checkboxes/
Share on other sites

I think I have been staring at this too long and am forgetting the simplest thing.

 

So what I did to test this is on the same page the import code is which list the check boxes, I added another form:

<form method="post" action="index3.php">
<input type="hidden" value="<?php echo $contacts->email_array[$key]?>" name="chk_email[]">
<input type="submit" value="show checked">
</form>

 

Then in the index3.php page I added:

<?php echo $_POST['chk_email']; ?>

 

but its not printing anything to the screen.

 

 

Well I did

print_r($_POST)

and it reutrned

ArrayArray ( [chk_email] => Array ( [0] => [email protected] ) ) 1

 

the email address [email protected] is the last email address which is displayed when I did the import and printed the checkboxes  to the screen, so it appears that the entire list of email addresses is not being stored in the array.

 

Is it because it is not looping the information into $_post ?

 

If I do:

<?php 
foreach($contacts->email_array as $key=>$val)
{
echo $contacts->email_array[$key];
}
?>

 

it shows all of the addresses in the array

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.