aeboi80 Posted April 8, 2010 Share Posted April 8, 2010 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 More sharing options...
taquitosensei Posted April 8, 2010 Share Posted April 8, 2010 you are 90% there. That line is fine. When you post that your array would be $_POST['chk_email'] any that are checked would be there. Link to comment https://forums.phpfreaks.com/topic/198037-post-an-array-of-checkboxes/#findComment-1039125 Share on other sites More sharing options...
aeboi80 Posted April 8, 2010 Author Share Posted April 8, 2010 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. Link to comment https://forums.phpfreaks.com/topic/198037-post-an-array-of-checkboxes/#findComment-1039138 Share on other sites More sharing options...
the182guy Posted April 8, 2010 Share Posted April 8, 2010 You should print out the entire post so you can see exactly what has been posted and what the keys and values are. To do that use: print_r($_POST); Link to comment https://forums.phpfreaks.com/topic/198037-post-an-array-of-checkboxes/#findComment-1039142 Share on other sites More sharing options...
taquitosensei Posted April 8, 2010 Share Posted April 8, 2010 plus even if it's only one value $_POST['chk_email'] is an array. So you should have done print_r($_POST['chk_email']); but doing the whole post variable is better, gives you an idea of what is actually being passed. Link to comment https://forums.phpfreaks.com/topic/198037-post-an-array-of-checkboxes/#findComment-1039147 Share on other sites More sharing options...
aeboi80 Posted April 8, 2010 Author Share Posted April 8, 2010 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 Link to comment https://forums.phpfreaks.com/topic/198037-post-an-array-of-checkboxes/#findComment-1039148 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.