Ashley Sheridan;10944879 wrote:bradgrafelman, that might not be too flexible though. I'm guessing from the example given that this form will grow larger and contain variable content, which might prove problematic if all the fields require a specific index in order to be handled by PHP.
I'd considered that, and forgot to mention the alternative. If you're careful with your form fields, then you can let PHP auto-index the array and use those indexes instead. New example:
td><input type="checkbox" name="delete[]" value="1"></td>
<td><input name="job[]" value="JOB1" type="text"></td>
</tr>
<tr class="tableDetail">
<td><input type="checkbox" name="delete[]" value="2"></td>
<td><input name="job[]" value="JOB2" type="text"></td>
EDIT: I'm stupid and wasn't thinking about the behavior of checkboxes. Oopsie. :o
EDIT2: Wait a minute... I think I missed the OP's question altogether.
@: You're wanting to only process the textboxes that you have changed from their default value (e.g. the one you specified in the HTML)?
If so, you'll have to do some more work so that PHP can identify these textboxes. How is PHP supposed to know if a textbox was changed or not - all it knows is what values you POST to it.
Two easy solutions for this are: 1) sessions, and 2) hidden form fields. For a session, you'd store the default value in the session for each textbox and when the form is submitted, loop through each textbox and see if the value POST'ed matches the one in the session - if not, then process the change.
For the hidden form fields, you'd do the same thing except you compare the textbox's value to the corresponding hidden form field's value (which, presumably, the user wouldn't alter).
Here's an example using hidden form fields:
<tr class="tableDetail">
<td><input type="checkbox" name="delete[]" value="DEL1"></td>
<td><input name="job[]" value="JOB1" type="text">
<input name="job_prev[]" value="JOB1" type="hidden"></td>
</tr>
and then to process it:
foreach($_POST['job'] as $id => $value) {
if(isset($_POST['job_prev'][$id])) {
if($value != $_POST['job_prev'][$id]) {
// textbox value (a.k.a. $value) was changed! process it here
}
} else {
// something went wrong... no matching default value was found in job_prev
// perhaps the user maliciously altered the form to try and break your script?
}