rgren925 Posted April 1, 2011 Share Posted April 1, 2011 Hi. I'm pretty new to php and javascript. Perhaps I'm going about this all wrong, so any ideas will be appreciated... I've got a php-generated form that calls an external javascript function (through onclick of button input) to validate an array of checkboxes. If the user presses ok on the javascript confirm box, it does a submit of the form. The checkboxes are a javascript, rather than php array: echo "<input type=\"checkbox\" name=\"attuids\" value=\"$dirReportUid\" class=\"CheckField\">$dirReportUid<br>\n"; What I need to do is get the array of checked boxes from my javascript array into a php array in the php script called by the submit action. Here's the javascript: function CheckboxTest(list) { total = ""; outArray = new Array(); outCount = 0; for (i=0; i < list.length; i++) { if (list[i].checked) { total += list[i].value + "\n"; } } if (total == "") { alert("No direct reports have been selected"); } else { alertMessage = "You have selected the following users\n"; alertMessage = alertMessage + "for Patrol Console deletion:\n\n"; alertMessage = alertMessage + total + "\n"; if (confirm(alertMessage)) { document.myForm.submit(); } } } Here's the php: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Patrol Console Audit</title> <link href="css/ConsoleAudit.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="javascripts/CheckboxProcess.js"></script> </head> <body> <h2>Patrol Console Audit</h2> <?php $patrolConsoleFile = "/home/rfg/ATT/console.userlist.csv"; $directReports = array(); $PATROLFILE = fopen("$patrolConsoleFile", "r"); $checkUid = "cr6228"; while (!feof($PATROLFILE)) { $fileLine = fgets($PATROLFILE); $patrolUserData = trim($fileLine); if (empty($patrolUserData)) { continue; } list ( $mgrData, $mgrDirReportUid, $mgrDirReportName, ) = explode(',', $patrolUserData); list ( $mgrName, $mgrUid, $mgrEmail, ) = explode(':', $mgrData); if ($mgrUid == $checkUid) { array_push($directReports, "$mgrDirReportUid $mgrDirReportName"); } } $firstName = "Jerry"; $lastName = "Garcia"; if (count($directReports) > 0) { echo "<h3> Direct Reports for $firstName $lastName</h3>\n"; echo '<form action="ProcessConsoleAudit.php" method="post" name="myForm">'."\n"; echo '<input name="checkedBoxes" type="hidden", id="checkedBoxes" value=""/>'; echo '<h4>Select users to retain Patrol Console access</h4>'."\n"; echo "<fieldset class=\"InputFields\">\n"; echo "<br><input type=\"checkbox\" name=\"CheckAll\" class=\"CheckField\" onclick=\"CheckUncheckAll(document.myForm.CheckAll,document.myForm.uids)\">Check All</br>\n"; echo "<br></br>"; foreach ($directReports as $dirReportUid) { echo "<input type=\"checkbox\" name=\"uids\" value=\"$dirReportUid\" class=\"CheckField\">$dirReportUid<br>\n"; } echo "</fieldset>\n"; echo "<div class=\"SubmitDiv\">\n"; echo '<input type="button" value="submit" class="SubmitButton" onclick="CheckboxTest(document.myForm.uids)">'."\n"; echo "</div>\n"; echo "</form>\n"; } else { echo "<br> No direct reports were selected<br>"; } ?> </body> </html> Thanks very much for any comments and/or ideas, Rick Quote Link to comment https://forums.phpfreaks.com/topic/232354-getting-javascript-array-to-php/ Share on other sites More sharing options...
KevinM1 Posted April 1, 2011 Share Posted April 1, 2011 In the future, please put your code within tags. Quote Link to comment https://forums.phpfreaks.com/topic/232354-getting-javascript-array-to-php/#findComment-1195318 Share on other sites More sharing options...
rgren925 Posted April 2, 2011 Author Share Posted April 2, 2011 I've got it nailed now. I didn't really understand the relationship between the javascript variable and the hidden variable on the php-generated form. Makes sense now. Quote Link to comment https://forums.phpfreaks.com/topic/232354-getting-javascript-array-to-php/#findComment-1195811 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.