0

I have a table with a list of clients, then a "modify" button then a "delete" button, and then a "add to mailing list" checkbox, each of these elements is its own form. There is also a selector at the end to chose which mailing list to add the address to. My problem is with these checkboxes. I have one submit button at the end of the table to add all of the checked emails to a file, but it only works on the last email address. Here is the code for the checkboxes:

 echo "<td>";
    echo "<form action=\"\" method=\"post\">";
    if($email!="" && $email!=null){
    echo "<label class=\"checkbox-inline\">
          <input type=\"checkbox\" name=\"mailing[]\" value=\"".$email[0][0]."\" title=\"".$email[0][0]."\"><span><i class=\"glyphicon glyphicon-envelope\"></i></span></label>";
    }else{
    echo "<label class=\"checkbox-inline\">
          <input type=\"checkbox\" disabled><span><i class=\"glyphicon glyphicon-envelope\"></i></span></label>";
    }
    echo "</form>";
    echo "</td>";

//... more code

//selector + submit

<form action="" method="post">
    <div class="col-sm-6 pull-right">
    <label class="control-label">Ajouter ces adresses à la liste:</label>
        <select class="form-control" name="liste">
            <option value=""></option>
            <?php
                $linkpdo = openConnection();
                $req = $linkpdo->prepare('SELECT * FROM AERA.mailing');
                $req->execute();
                $lists = $req->fetchAll();
                if(count($lists)<>0){
                    for ($i = 0; $i < count($lists) ; $i++){
                        echo "<option value=\"".$lists[$i][0]."\">";
                        echo $lists[$i][1];
                        echo "</option>";
                    }
                }
            ?>
        </select>
    </br>
        <button type="submit" class="btn btn-info" id="clickAll">Ajouter</button>

How can I get all of the checkbox values? Or is there another way to go about it? Thanks

UPDATE

Here is how I am currently handling the results:

if(!empty($_POST['mailing'])) {
                foreach ($_POST['mailing'] as $key => $value){
                    $mailing=$_POST['mailing'][$key];
                     if(stripos(file_get_contents($filename), $mailing)!== false){
                        echo '<div class="container">
                            <div class="col-sm-6 col-sm-offset-3 alert alert-info">
                                <p class="text-center">Vous avez essayé d\'insérer des doublons.</br>Ces valeurs n\'ont pas été prises en compte</p>
                            </div>
                        </div>';
                    }else{
                        $stringIn.=$mailing.", ";
                    }
                }
            }
Jessica Chambers
  • 1,246
  • 5
  • 28
  • 56
  • Not sure to well understand but I think you must have only one form that contain all the checkboxes and the submit button. – Toto Apr 22 '16 at 10:47
  • Do you know how I could do that without having a submit button on each row of my table? – Jessica Chambers Apr 22 '16 at 11:14
  • Put the whole table in an unique form. – Toto Apr 22 '16 at 11:52
  • it doesn't matter if there are other forms inside that form? – Jessica Chambers Apr 22 '16 at 12:05
  • It DOES matter, you can submit only one form at a time and you can't include a form in another one. You have to put everything you want to submit in an unique form that contains the submit button and all the checkboxes. – Toto Apr 22 '16 at 12:08
  • @Toto ok.. Do you think there's a way to store the values of the checked boxes with javascript? (I don't know javascript very well) – Jessica Chambers Apr 22 '16 at 14:12

1 Answers1

0

Why don't you make a html form and than a php script?

you can see an example here: Getting checkbox values on submit

Community
  • 1
  • 1
  • it is a html form; I just had to mix in some php for other reasons. Do you mean the result handling? – Jessica Chambers Apr 22 '16 at 10:14
  • yes I see the html code. I usually use to separate the html from the php... when it is possible:-). Yes i mean the result handling. You can also find here an example http://stackoverflow.com/questions/4997252/get-post-from-multiple-checkboxes . –  Apr 22 '16 at 11:43