0

for some reason I can't get the $_FILES array to include the upload as selected on my form. From what i have read the form looks ok, and all the other variables are received just fine.

Each time I submit the form the var_dump for the $_FILES array has 0 entries.

For this post i have removed the other fields for the sake of brevity since they are working.

<form name="addFact" id="addFact" action="add_fact.php" method="post" enctype="multipart/form-data" onsubmit="return validateStatus();" >
    <input type="file" id="myImage" name="myImage" style="width:450px;"/><br />
</form>

And after I reload I use the following to check the $_FILES array:

echo "- Files - <br>\n";
echo "<pre>\n";
var_dump($_FILES);
echo "</pre>\n";

but the result is empty every time:

Files: array(0) { }

Update sorry, didnt realize validate status was still in there .. but this is the JS that checks whether to submit the form or not

function validateStatus() {
    jQuery("#addFact").validationEngine({scroll: false});
    var valid = $("#addFact").validationEngine('validate');
    if (valid == true) {
        submitForm('addFact');
    }
    return false;
}

Though I doubt that is part of the issue as the form submits successfully with all attributes still set including the file field , etc.

oh ..and lol .. another function .. :) ... here is the submt form function:

function submitForm(formName,message) {
    $.ajax({
        data: $("#" + formName).serialize(),
        type: $("#" + formName).attr('method'),
        url: $("#" + formName).attr('action'),
        success: function(response) {
            $('#load_target').html(response);
        }
    });
    return false;
}

load_target is the div on the index page I am loading this php file into with ajax. - hope that is all clear now :)

Also, to belay any conrens of the form not posting anything .. here are the results for the post var_dump

array(11) {
  ["action"]=>  string(4) "save"
  ["category"]=>  string(1) "3"
  ["startDate"]=>  string(10) "09-27-2012"
  ["expireDate"]=>  string(10) "11-27-2012"
  ["title"]=>  string(10) "Test Title"
  ["subtitle"]=>  string(10) "Test Title"
  ["include_image"]=>  string(3) "yes"
  ["img_loc"]=>  string(4) "left"
  ["img_size"]=>  string(2) ".3"
  ["scroll"]=>  string(1) "1"
  ["fact_text"]=>  string(27) "there's something about her"
}
7
  • are you actually uploading a file when you test it? the index in $_FILES may not exist if the input field is left blank. Commented Sep 27, 2012 at 23:16
  • 4
    What's "validateStatus()" doing? Could it be manipulating that field? Commented Sep 27, 2012 at 23:16
  • validate status checks for all fields being populated (required fields that is) and then submits the form if all is good, sorry about that. Commented Sep 27, 2012 at 23:37
  • Yes i am selecting a file in the form field and submitting the form ... though tie $_FILES does not seem to reflect it. Commented Sep 27, 2012 at 23:38
  • 1
    From the jQuery serialize documentation: "Data from file select elements is not serialized." Commented Sep 28, 2012 at 1:18

1 Answer 1

1

if you are using jquery mobile add the data-ajax="false" to the form tag

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.