2

I have a simple field somewhere in my document. Now I want to CREATE a form with jQuery, add this input field to it and submit it via Javascript.

Something like this:

var newform = $( document.createElement('form') );
newform.attr("method","post")
       .attr("action",action)
       .attr("enctype","multipart/form-data");
       .append($("#file").clone())
       .submit();

Unfortunately, $_FILES gives me error code 4: "No file submitted". I tried this with simple Text fields, and it worked for them, their value has been submitted too. Just the file-upload won't work.

Any suggestions how that could be done?

2
  • 1
    AFAIK file is contained in $_FILES, not in $_POST Commented Dec 19, 2009 at 20:46
  • of course, how stupid. :( Anyways, I'm getting error code 4, "no file was submitted" Commented Dec 19, 2009 at 20:50

1 Answer 1

1

I think it has to do with the fact that $("#file").clone() would cause the input appended to the form to have the same id '#file'.

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.