freakus_maximus Posted October 4, 2006 Share Posted October 4, 2006 OK, I have been trying to sort this out for sometime now with no luck. No matter how I seem to try and pass a hidden value it is not coming through. This is on an 'edit' page, which all the current values are pulled in and displayed and the checkboxes/textareas can now be updated. The number of tasks (the checkboxes and textareas) will always be different since users can add multiple tasks during the entry process.I tried a foreach($_POST as $k => $v) with no luck, everything else shows up when I echo from that, but no the "taskids" array I need.This is the code from the form (my queries and all that work fine):[code]$result = mysql_query ('SELECT * FROM nabuild_task WHERE parent_cr = "'.$crnum_req.'" ORDER BY task_id ASC') or die ("Query failed"); while($row=mysql_fetch_row($result)){ $task_id = $row[0]; $parent_cr = $row[1]; $task_done = $row[2]; $task_desc = $row[3]; If ($task_done == "on"){ $taskcheck = ('checked="checked"');}else{$taskcheck = ('');} echo ('<TD><P align="left"><INPUT id="chbx[]" name="chbx[]" type="checkbox" '.$taskcheck.'></P></TD>'); echo ('<TD colSpan="1"><TEXTAREA id="desc[]" name="desc[]" rows="3" cols="60">'.$task_desc.'</TEXTAREA></TD>'); echo ('<input type="hidden" id="taskids[]" value='.$task_id.'>'); //Yes, I realize this would not work, but trying to show what I have tried } [/code]Here is the processing code (this is simplistic just so I can get down that the values are coming through the way I need):[code] foreach ($_POST['desc'] as $k => $descrip) { if ($descrip > '') { $cb = isset($_POST['chbx'][$k]) ? 'on' : ''; echo ('Checkbox: '); echo ($cb); echo ('<br>'); echo ('Description: '); echo ($descrip); echo ('<br>'); } }[/code]Basically, in the processing code, I need to be able to pull in the correct associated task_id. I need to do this so when I update the table, it updates the correct id. But I cannot seem to get a handle around passing the value of task_id and have it properly associated.Any help is much appreciated! Quote Link to comment Share on other sites More sharing options...
Hi I Am Timbo Posted October 4, 2006 Share Posted October 4, 2006 you would have to serialize() the array. echo '<input type="hidden" name="array" id="array" value="'.serialize($array).'">'Then when you $_GET or $_POST you have to unserialize it.$array = unserialize($_POST['array']);Sessions may be a better option.session_start();$_SESSION['array'] = $array;This way you don't have to pass all of that data to the user. Quote Link to comment Share on other sites More sharing options...
freakus_maximus Posted October 4, 2006 Author Share Posted October 4, 2006 THanks Timbo for the response. I was not having any luck constucting the serialized array. I did however figure out a little more with getting the hidden values passed, but I have a new problem. (Did not want to start another thread)This is almost the correct output, but as you can see the checkbox for id 17 should not be checked. This is the checkbox value for 18. It's seems to just be dropping the 'on' values first no matter what, which does not seem right considering the foreach loop:Row ID: 16Checkbox: onDescription: this should be checked it is number 16Row ID: 17Checkbox: onDescription: this should NOT be checked it is number 17Row ID: 18Checkbox: offDescription: this should be checked it is number 18In the form I added this to pass the taskids (the rest of the form code is the same as before):[code] echo ('<input type="hidden" id="taskids[]" name="taskids[]" value='.$task_id.'>');[/code]Process form:[code] foreach ($_POST['desc'] as $k => $descrip) { if ($descrip > '') { $cb = isset($_POST['chbx'][$k]) ? 'on' : 'off'; //I put the off here just to see what was happening $taskid = ($_POST['taskids'][$k]); echo ('Row ID: '); echo ($taskid); echo ('<br>'); echo ('Checkbox: '); echo ($cb); echo ('<br>'); echo ('Description: '); echo ($descrip); echo ('<br>'); } }[/code]Any ideas why two the id and description are associated right but no the checkbox when it runs through the loop? Quote Link to comment Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 I think checkboxes are only set if they are checked. I'm not positive though. Quote Link to comment Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 so if the checkbox is checked, it is set to on, but if it is unchecked, it is not set. (isset($_POST['checkbox']) == false) Quote Link to comment Share on other sites More sharing options...
printf Posted October 5, 2006 Share Posted October 5, 2006 Your form input checkbox array, need to have the task id assigned to it, so you know what box was checked![code]echo ('<TD><P align="left"><INPUT id="chbx[' . $task_id . ']" name="chbx[' . $task_id . ']" type="checkbox" '.$taskcheck.'></P></TD>')[/code]me! Quote Link to comment 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.