Jump to content

rgren925

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rgren925's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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.
  2. 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
  3. Hi. I've tried just about everything I can think of, but no success. Here's the perl I'm trying to convert: $socket = new IO::Socket::INET ( PeerAddr => 'localhost', PeerPort => 1500, Proto => 'tcp'); if ($socket->send("$token\n")) { $data = <$socket>; } Here's what I've currently got in PHP: $socket = fsockopen('localhost', 1500, $errno, $errstr); fwrite($socket, "$token\n"); $data = fread($socket, 1024); fclose($socket); I've confirmed the socket descriptor is populated and the fwrite is working. The fread just hangs. I've tried fputs/fgets in various combinations, but the read/get always hangs. Any ideas? Thanks very much, Rick
  4. okay. got it. $i was inside single quotes. Needs to look like this: echo '<input type="hidden" name="next_start" value='.$i.' />'; Jon - Thanks very much for getting me on the right track.
  5. I'm thinking the $end variable isn't right. This works except that $i isn't being saved across iterations (first iteration displays 0; subsequent display "$i") echo '<form name="PHP" action="'.$PHP_SELF.'" method="POST" />'; if (isset($_POST['next_start'])) { $i = $_POST['next_start']; } else { $i = 0; } $end = 5; if ($i < $end) { echo "<p>$i</p>"; $i++; } echo '<input type="hidden" name="next_start" value="$i" />'; echo '<input type="submit" name="click_php" value="PHP form" />'; echo '</form>';
  6. Still not quite there. The initial call generates 0 1 2 3 4 on separate lines followed by the submit button. What I'm looking for is 0; hit submit; 1; hit submit; etc. When I do hit submit on this I get an endless loop of $end; $ene; $enf; :: $enz; $eoa; :: etc.
  7. Thanks Jon. I think I'm getting closer to understanding this, just not certain how to fit it all together. This generates an endless loop of zeroes -- no form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php echo '<html xmlns="http://www.w3.org/1999/xhtml">'; echo '<head>'; echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; echo '<title>PHP Loop Test</title>'; echo '</head>'; echo '<body>'; echo '<form name="PHP" action="'.$PHP_SELF.'" method="POST" />'; if (isset($_POST['next_start'])) { $i = $_POST['next_start']; } else { $i = 0; } $end = $i + 5; while ($i < $end) { echo "<p>$i</p>"; } echo '<input type="hidden" name="next_start" value="$end" />'; echo '<input type="submit" name="click_php" value="PHP form" />'; echo '</form>'; echo '</body>'; echo '</html>'; ?>
  8. Thanks for the reply Jon. Sorry to seem obtuse, but my attempt to do what i thought you were suggesting generated the same endless loop. Is it because I'm reinitializing the counter to zero on each iteration? If so, how do i get around that? If not, ???? Thanks, Rick <?php $i = 0; while ($i < 5) { echo '<html xmlns="http://www.w3.org/1999/xhtml">'; echo '<head>'; echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; echo '<title>PHP Loop Test</title>'; echo '</head>'; echo '<body>'; echo '<form name="PHP" action="'.$PHP_SELF.'" method="POST">'; echo '<input type="submit" name="click_php" value="PHP form" />'; echo '</form>'; if($_POST['click_php']) { echo "This is from PHP form ==> $i"; $i++; } echo '</body>'; echo '</html>'; } ?>
  9. Hi. I'm a PHP newbie. I'm trying to generate a form in a loop. The user would press the submit button and the loop would iterate. Ultimately, it's for a project that will read a large flat file and get 500 lines at a time that the user could page through. But, my little test case is far simpler. just increment a counter every time the user presses submit. What I've tried doesn't work; causes an endless loop rather than stopping each time for the user to hit submit. I've just cobbled this together from things I've seen here and elsewhere, so please be gentle. Any help would be greatly appreciated. Thanks, Rick <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP Loop Test</title> </head> <body> <?php $i = 0; while ($i < 5) { echo '<form name="PHP" action="'.$PHP_SELF.'" method="POST">'; echo '<input type="submit" name="click_php" value="PHP form" />'; echo '</form>'; if($_POST['click_php']) { echo "This is from PHP form ==> $i"; $i++; } } ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.