hinchcliffe Posted October 24, 2007 Share Posted October 24, 2007 Hi Guys, I was wondering if you could give me a bit of help. I have a e-mail list that I would like to be able to select witch user is going to be e-mailed, also it would have the check all / uncheck all buttons. I have an none working example of what I need to code here: http://bbold.com/strataman/admin.php Here is what I got so far. <!-- Includes Header start --> <?php include('includes/header.php'); ?> <!-- Includes Header Ends / Content Starts --> <h1>E-mail Subscribers:</h1><br /> <div id="listings"> <center><h3>Mailing List</h3></center> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } // End --> </script> <?php // Connect to DataBase include 'includes/dbconnect.php'; // Query database $query = "SELECT * FROM mail"; $rs = mysql_query($query); echo 'Subscription List <br /><br />'; echo "<form name=\"myform\" action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">" . "<br />"; while($row = mysql_fetch_array($rs)) { echo "<input type=\"checkbox\" name=\"list\" value=\"" .$row['email']. "\" >" . " <a href=\"mailto:" . $row['email'] . "\">" . $row['email'] . "</a><br />"; } // If summit button clicked do this!! if($_POST['submit']) { echo $_POST['list']; } ?> <br /> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> <br/> Send an e-mail:<br /> <textarea name="message" rows="10" cols="100"></textarea><br/><br /> <input type="submit" name="submit" value="Send"> <br /><br /> Attach a file:<br /> <input type="file" name="file"> </form> </div> <!-- Includes Footer Starts --> <?php include('includes/footer.php'); ?> <!-- Includes Footer Ends --> Quote Link to comment https://forums.phpfreaks.com/topic/74616-checkbutton-e-mail-list-with-check-all/ Share on other sites More sharing options...
marcus Posted October 24, 2007 Share Posted October 24, 2007 name=\"list[]\" print_r($_POST['list']); alt: foreach($_POST['list'] AS $email){ echo $email . "<br />\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/74616-checkbutton-e-mail-list-with-check-all/#findComment-377156 Share on other sites More sharing options...
hinchcliffe Posted October 24, 2007 Author Share Posted October 24, 2007 Warning: Invalid argument supplied for foreach() in /home/bbold07/public_html/strataman/admin.php on line 50 if($_POST['submit']) { foreach($_POST['list'] AS $email){ echo $email . "<br />\n"; } } ?? Quote Link to comment https://forums.phpfreaks.com/topic/74616-checkbutton-e-mail-list-with-check-all/#findComment-377159 Share on other sites More sharing options...
marcus Posted October 24, 2007 Share Posted October 24, 2007 Did you change the name of the checkbox to list[] ? Quote Link to comment https://forums.phpfreaks.com/topic/74616-checkbutton-e-mail-list-with-check-all/#findComment-377174 Share on other sites More sharing options...
hinchcliffe Posted October 24, 2007 Author Share Posted October 24, 2007 Oh ok, Thanks, that works good, Now I just have one more problem. Since you changed the last name, my javascript for the check all isn't working. I'll post the code... <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } // End --> </script> <?php // Connect to DataBase include 'includes/dbconnect.php'; // Query database $query = "SELECT * FROM mail"; $rs = mysql_query($query); echo 'Subscription List <br /><br />'; echo "<form name=\"myform\" action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">" . "<br />"; while($row = mysql_fetch_array($rs)) { echo "<input type=\"checkbox\" name=\"list[]\" value=\"" .$row['email']. "\" >" . " <a href=\"mailto:" . $row['email'] . "\">" . $row['email'] . "</a><br />"; } // If summit button clicked do this!! if($_POST['submit']) { foreach($_POST['list'] AS $email){ echo $email; } } ?> <br /> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> <br/> Send an e-mail:<br /> <textarea name="message" rows="10" cols="100"></textarea><br/><br /> <input type="submit" name="submit" value="Send"> I think it's just this part thats messing it up <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> I already tried changing the (document.myform.list) to (document.myform.list[]). Any other suggestions? Thanks for your help so far. Quote Link to comment https://forums.phpfreaks.com/topic/74616-checkbutton-e-mail-list-with-check-all/#findComment-377190 Share on other sites More sharing options...
marcus Posted October 24, 2007 Share Posted October 24, 2007 form.elements[i].checked=true change form with your form name.[/code] Quote Link to comment https://forums.phpfreaks.com/topic/74616-checkbutton-e-mail-list-with-check-all/#findComment-377194 Share on other sites More sharing options...
hinchcliffe Posted October 24, 2007 Author Share Posted October 24, 2007 Sorry, I'm not very good at javascript could you explain it better? Do you want me to change this section? echo "<form name=\"myform\" action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">" . "<br />"; Quote Link to comment https://forums.phpfreaks.com/topic/74616-checkbutton-e-mail-list-with-check-all/#findComment-377201 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.