Page 1 of 1

Beginner - How to process more checkboxes - arrays?

Posted: Thu Mar 18, 2004 2:02 am
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....

Posted: Thu Mar 18, 2004 2:53 am
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

hmm, not quite sure

Posted: Thu Mar 18, 2004 2:59 am
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?

Look at this please

Posted: Thu Mar 18, 2004 3:18 am
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

problem solved

Posted: Thu Mar 18, 2004 3:39 am
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

?>