Beginner - How to process more checkboxes - arrays?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
doro44
Forum Newbie
Posts: 4
Joined: Thu Mar 18, 2004 2:02 am
Contact:

Beginner - How to process more checkboxes - arrays?

Post by doro44 »

Hi guyz, I am new in PHP.So I hope someone helps me.I have first page called index.html.In that page there are few checkboxes :

<form action="process.php">
<input type="checkbox" name="mail[]" value="1"> mail to user 01</br>
<input type="checkbox" name="mail[]" value="2"> mail to user 02</br>
<input type="checkbox" name="mail[]" value="3"> mail to user 03</br>
<input type="submit" name="Submit">
</form>


When the submit button will be pressed it should send all checked checkbox values to file process.php.Now I want that process.php will send emails to all checked users.How should process.php look like?I found on internet that it should be done with these brackets [] and with arrays.
Thanks for all answers....
yerupalleyskumar
Forum Newbie
Posts: 8
Joined: Wed Mar 17, 2004 11:04 pm
Location: Tokyo
Contact:

Post by yerupalleyskumar »

<form action="process.php">
<input type="checkbox" name="mail[]" value="1"> mail to user 01</br>
<input type="checkbox" name="mail[]" value="2"> mail to user 02</br>
<input type="checkbox" name="mail[]" value="3"> mail to user 03</br>
<input type="submit" name="Submit">
</form>

in php u can submit the values of check box values by submitting the form by POST mehtod
like
<form action="process.php" method="POST">
and in php
$_POST['mail'] will give the array of mailuser ids
hope this will help
doro44
Forum Newbie
Posts: 4
Joined: Thu Mar 18, 2004 2:02 am
Contact:

hmm, not quite sure

Post by doro44 »

I was trying to do it but it was not working for me.I dont know how exactly to do it.Could please someone be more specificaly?
doro44
Forum Newbie
Posts: 4
Joined: Thu Mar 18, 2004 2:02 am
Contact:

Look at this please

Post by doro44 »

index.html:

Code: Select all

<form action="process.php" method="POST">
<input type="checkbox" name="mail&#1111;]" value="user1@domain.sk;"> mail to user 01</br>
<input type="checkbox" name="mail&#1111;]" value="user2@domain.sk"> mail to user 02</br>
<input type="submit" name="Submit">
</form>
process.php:

Code: Select all

<?php

// check to be sure at least one option was selected

$mail = $_POST&#1111;'mail'];
if (count($mail) > 0) &#123; 
      // loop through the array
      for ($i=0;$i<count($mail);$i++) &#123; 

            // do something - this can be a SQL query, echoing data to the browser, or whatever
            echo "<li>$mail&#1111;$i] \n"; 
			mail("$mail&#1111;$i]","blablabla","message","From: administrator@domain.sk");

      &#125; // end "for" loop

&#125; // endif

?>
It is saying always server error in line where is mail function.
please help
doro44
Forum Newbie
Posts: 4
Joined: Thu Mar 18, 2004 2:02 am
Contact:

problem solved

Post by doro44 »

<?php

// check to be sure at least one option was selected

$mail = $_POST['mail'];
if (count($mail) > 0) {
// loop through the array
for ($i=0;$i<count($mail);$i++) {

// do something - this can be a SQL query, echoing data to the browser, or whatever
echo "<li>$mail[$i] \n";
$to="$mail[$i]";
mail("$to","blablabla","message","From: administrator@domain.sk");

} // end "for" loop

} // endif

?>
Post Reply