views:

96

answers:

2

Well I'm having some really weird trouble, this is what happens:

This is the environment: I have a modal panel that has to be able to hold several "steps", first you have to upload a file, then the file is processed and from this processing result, I have to generate some html to fill the next step.

This is what I do: I'm uploading a file within a modal panel's form in either one of two ways (from some url, or from your local hard drive using the file type input and $_FILES), using jquery's $.ajaxForm to submit it to the php file that processes it. Once processed, I have all the objects that I need filled with info, that are used in some template that I include and then with it's contents filled into a text variable I json_encode them in order to be appended into my modal panel's second form.

So far... so good... until I found out that when I choose "from url" and disable file input, everything works just fine, but when I enable the file input upload, the result html that I get from the include from the template is broken (yeah... you must be saying WTF?, but is true 0_0 I tryed EVERYTHING until I isolated where the error was hiding...). It get some "PRE" html tag added at the beggining of the html result and every tag is cast to upper case and all ending tags have its "<" and ">" replaced by it's entity counterpart (like & lt; and so). I saw that by "alerting" the raw HTML result in the form's callback (and obviously by the damage caused to the result form). Any ideas about what can be happening??

Thanks in advance!!!

PS: I got verbose... :P

+1  A: 

You should probably give some detail about the framework / templating engine you're using, because it sounds like that's where the problem is. Seems like something about the file input version of your form is driving it insane -- likely the enctype="multipart/form-data" you have to use for file uploads. You could test that part by adding the enctype attribute to your non-file dialog and seeing if it goes insane then too.

If your templating engine is responsible, fixing the problem will probably involve either upgrading it or debugging its guts.

chaos
Not using any templating engine... can't afford the overhead... basically the templates are "faked" by processing outside and then including the html to use the generated data. About the enctype, is set ok, and even the other stuff sent in the same form (if I disable the file input) don't do anything funny... I dunno... =(Thanks!!
Juan Manuel
+1  A: 

As far as I know, you cannot submit an upload with ajax like that. You can fake it by creating a form inside an <iframe> and then submitting it, but I don't think you can use pure ajax to do it. I am a prototype user, but I think the same is true for jquery or any other library.

arbales
The only problem I have is that I obtain that funny behavior... but as far as file uploading... the file is uploaded just ok!That's because I'm not faking the submit, but really submiting, processing the submission and catching the event.Look around for jquery's ajaxForm :)
Juan Manuel
So your observing the form > validating the form, storing your inputs as json > submitting your file > showing a new panel? What is the 'result html' your creating? I looked at jquery ajaxForm — I didn't realize it had a built-in iframe option — seems handy that it does it for you.
arbales
Only the answer comes as json... the submitting of the form goes in "post", file too.
Juan Manuel