tags:

views:

178

answers:

5

Sometimes, multiple times a day in fact, users of my web application are submitting a certain form which has about a dozen form fields, half of which are hidden fields, and half of the $_POST data is simply not present in the processing script. Note that the fields that are not present are at the very bottom of the form. I know this because this raises a fatal error, and an email is dispatched to me which includes the post data.

And of course, neither I nor any of the developers on my team can reproduce the problem.

Flash is involved in the process, as I'm using a library called Uploadify to display a progress meter. Here is the flow...does anyone have ANY ideas at all why some of the post data would be getting wiped out?

  • User visits edit screen for a page in the CMS I am using.
  • Record id for the page is put into a form as a hidden value.
  • User clicks the Uploadify browse button and selects a file (only single file selection is allowed).
  • User clicks Submit button for my form.
  • jQuery intercepts the form submit action, triggers Uploadify to start uploading, and returns false for the submit action (manually cancelling the form submit event so that Uploadify can take over).
  • Uploadify uploads to a custom process script.
  • Uploadify finishes uploading and triggers the Javascript completion callback.
  • The Javascript callback calls $('#myForm').submit() to submit the form.

This happens on multiple browsers (Firefox 3.5, 3.6, Safari, Internet Explorer 7, 8) and multiple platforms (Mac OS 10.5, 10.6 and Windows XP, 7).

+1  A: 

Is the target for the file upload (Uploadify) the same script as the <form>? If so, Uploadify won't send along any information (i.e., other form fields) with the file upload unless you explicitly specify it in the scriptData configuration option. Maybe the errors are being caused by these uploads hitting the page, which results in requests that lack certain fields.

awgy
Negatory; the form has a different action than the 'script' parameter I'm sending to Uploadify. And I am for sure passing via scriptData the necessary information the upload script needs to do the uploading.
Chad Johnson
+1  A: 

Are you doing anything with javascript to the data? If so, some users might not have js enabled and could be causing the problem. Try running the form with javascript disabled.

edit: helps to read the whole post. yeah, chances are that people are running the form without javascript enabled.

DForck42
Good question, but unfortunately the error does not happen when Javascript is disabled, and the upload still happens.
Chad Johnson
+1  A: 

My first thought is invalid html. You say hidden fields at the end. Maybe some of the data embedded in them is not properly prepared or escaped.

Since you do get some of the data, I would maybe start using jquery to create some type of a checksum of the form elements and values it knows about, and send this aggregated checksum along with the form post. Depending on whether or not you have trouble getting it to work could be very revealing to your problem.

You might also try to find out the content-length of the http request sent by the browser. Maybe change webserver log config. It might be sending the data, and it's being mishandled by your server/script.

chris
Good thought, but so far I haven't found anywhere that this may be the case in the code.
Chad Johnson
A: 

I think your flow may be wrong. Shouldn't you be doing

1> Browse for file 2> After selecting file automatically starts uploading. 3> User selects submit button

That way you avoid the complication of intercepting things.

Here is a snippet of my flow:

var fname = '';
$(document).ready(function() {
    $('#upload').hide();
    $('#submit_btn').hide();

    if($('#id').val()) {
        $('#upload').show();
    }
    $('#upload').uploadify({
        uploader:   'js/uploadify/uploadify.swf',
        script:     'upload.php',
        folder:     '_holder',
        auto:       true,
        cancelImg:  'images/cancel.png',
        buttonText: 'Upload File',
        width:      '120',
        onComplete: function(event, queueID, fileObj, reponse, data) {
            fname = fileObj.name;
            $("#status_msg").html( 'File Is Uploaded.' );
            $('#submit_btn').show();
       }
    });
});

Then of course I do other processing on the file from the submit_btn.

Gutzofter
I don't see how changing the flow in that manner will solve the problem. Thanks for posting though.
Chad Johnson
@chad when checking for $_POST['data'] are you using isset or array_key_existsExample #2 array_key_exists() vs isset()http://php.net/manual/en/function.array-key-exists.phpmaybe somehow the hidden values are being set to null
Gutzofter
A: 

Hi Chad, If the fields that are NOT coming through are defined after the file-upload field in the same form, this could very well be your problem.

If this is the case, you will have to split the upload-form and data-form each with it's own action(best solution), or specify all your fields 'before' the upload form (2nd choice)

Riaan