POST to Array trouble
Posted: Tue Jan 26, 2010 7:52 am
Hi Chaps,
I have a Query that calculates a Quote for a job/jobs for a given project.
As there can be more than one job for a project, I have to loop through the query and present the data in a table.
Users have the option to 'override' the estimated quote and enter a 'custom quote'.
The ProjectID, JobID and TableInfo are part of my 1st Array, the estimated/custom quote figure and the 'override' option are part of my 2nd Array.
The information is then POSTed to a script file that joins the information together and then updates the relevant Table/JobID based on the figures and override options.
Example of HTML Code:
CompleteQuoteSingle.php
My problem is:
The Override option only gets passed to the Array, if selected. This means that if I have two jobs, and I select the override option for the second job, the array looks like this:
Is there a way of POSTing a default value of 'n' for the 'jobadminquote' checkbox, so that the above would look like:
I have a Query that calculates a Quote for a job/jobs for a given project.
As there can be more than one job for a project, I have to loop through the query and present the data in a table.
Users have the option to 'override' the estimated quote and enter a 'custom quote'.
The ProjectID, JobID and TableInfo are part of my 1st Array, the estimated/custom quote figure and the 'override' option are part of my 2nd Array.
The information is then POSTed to a script file that joins the information together and then updates the relevant Table/JobID based on the figures and override options.
Example of HTML Code:
Code: Select all
<form action="CompleteQuoteSingle.php" method="post" enctype="multipart/form-data"> <table border="0" cellpadding="0" cellspacing="0"> <caption><input type="submit" id="button" value="Submit" /></caption> <tr> <th>Project No.</th> <th>Project Title</th> <th>Job Title</th> <th>Type</th> <th>Language</th> <th>Deadline</th> <th>Document Format</th> <th>Pages</th> <th>Word Count</th> <th>Net Total</th> <th>EN Proofreading Cost</th> <th>Total</th> <th>Admin Override</th> </tr> <script type="text/javascript"> $(function() { var jobquote = $('#jobquote_328'); var value = jobquote.val(); $('#jobadminquote_328').click(function() { if (jobquote.attr('readonly')) { jobquote.removeAttr('readonly'); jobquote.val(''); } else { jobquote.attr('readonly', 'readonly'); jobquote.val(value); } }); }); </script> <tr> <td>1111</td> <td>QuickTrace - Project Template</td> <td>TEST JOBSHEET</td> <td>DTP</td> <td>EN</td> <td>31/12/2010</td> <td>MS Word</td> <td>20</td> <td>280</td> <td>£350.40</td> <td>£ 8.40</td> <td>£<input type='text' name='jobquote[]' id="jobquote_328" value="358.80" readonly="readonly" /></td> <td><input type="checkbox" name="jobadminquote[]" id="jobadminquote_328" value="y" /></td> </tr><input type="hidden" name="jobinfo[]" value="tbl_jobs:328:1111" /> <script type="text/javascript"> $(function() { var jobquote = $('#jobquote_335'); var value = jobquote.val(); $('#jobadminquote_335').click(function() { if (jobquote.attr('readonly')) { jobquote.removeAttr('readonly'); jobquote.val(''); } else { jobquote.attr('readonly', 'readonly'); jobquote.val(value); } }); }); </script> <tr> <td>1111</td> <td>QuickTrace - Project Template</td> <td>TEST</td> <td>DTP</td> <td>CZ</td> <td>31/12/2010</td> <td>InDesign CS4</td> <td>654</td> <td>280</td> <td>£ 50.40</td> <td>£ 0.00</div></td> <td>£<input type='text' name='jobquote[]' id="jobquote_335" class='price' value="50.40" readonly="readonly" /></td> <td><input type="checkbox" name="jobadminquote[]" id="jobadminquote_335" value="y" /></td> </tr><input type="hidden" name="jobinfo[]" value="tbl_jobs:335:1111" /> </table>Code: Select all
$allowed_tables = Array('tbl_jobs','tbl_jobtransline','tbl_jobxml'); // to prevent SQL injection
$i = 0;
foreach($_POST['jobinfo'] as $var) {
$arr = explode(':', $var);
if(in_array($arr[0], $allowed_tables)) {
$table = $arr[0];
$rowid = $arr[1];
$projid = $arr[2];
$setprice = $_POST['jobquote'][$i];
$adminoverride = $_POST['jobadminquote'][$i];
$i++;
if(is_numeric($rowid)){
if($adminoverride=='y') {
// run your SQL query here to update $table where row matches $rowid
$query = sprintf("
UPDATE $table
SET jobquote='$setprice', jobquotecomplete='y', jobadminquote='y'
WHERE jobid=$rowid");
//$result = mysql_query($query, $conndb2) or die(mysql_error());
//$mess = $ref = $_SERVER['HTTP_REFERER']; header( 'refresh: 0; url=../../projects/project_details.php?id='.$projid);
}
else {
// run your SQL query here to update $table where row matches $rowid
$query = sprintf("
UPDATE $table
SET jobquote='$setprice', jobquotecomplete='y', jobadminquote='n'
WHERE jobid=$rowid");
//$result = mysql_query($query, $conndb2) or die(mysql_error());
//$mess = $ref = $_SERVER['HTTP_REFERER']; header( 'refresh: 0; url=../../projects/project_details.php?id='.$projid);
}
}
}
}The Override option only gets passed to the Array, if selected. This means that if I have two jobs, and I select the override option for the second job, the array looks like this:
Question:Array
(
[jobquote] => Array
(
[0] => 358.80
[1] => 100
)
[jobinfo] => Array
(
[0] => tbl_jobs:328:1111
[1] => tbl_jobs:335:1111
)
[jobadminquote] => Array
(
[0] => y
)
)
Is there a way of POSTing a default value of 'n' for the 'jobadminquote' checkbox, so that the above would look like:
I hope this is clear?![jobadminquote] => Array
(
[0] => n
[1] => y
)