Welcome Guest, Not a member yet? Register   Sign In
send input file info via ajax
#3

The point is the following:

To give the input and select validation statements their data to check:

Code:
$this->form_validation->set_rules('product_title', 'Product Name', 'trim|required|is_unique[products.name]');
$this->form_validation->set_rules('price', 'Price', 'trim|required|callback_check_price');
$this->form_validation->set_rules('categories', 'Product\'s Category', 'required');

I got their values using val() and passed them as data parameters in the ajax request:
Code:
data: {
                product_title:pt,
                price: pp,
                categories: cid
            },

An that works.

What additional parameter do I need to pass so that the following CI method can do it's job?
Code:
if ( ! $this->upload->do_upload()) {... (the file input's name is userfile, the CI standard).

I tried the following from the SO link you gave me:
Code:
var fd = new FormData(document.getElementById("uploadImage"));
fd.append("label", "WEBUPLOAD");

and then modified the data parameter like so:
Code:
data: {
                product_title:pt,
                price: pp,
                categories: cid,
                userfile : fd
            },

however when I try to submit the form I get the following console error:
Code:
Argument 1 of FormData.constructor does not implement interface HTMLFormElement.

Is there something similar I can do to get the needed value from the file field so that CI can upload it?
Reply


Messages In This Thread
send input file info via ajax - by dzoniboj - 02-03-2015, 10:07 AM
RE: send input file info via ajax - by mwhitney - 02-03-2015, 12:56 PM
RE: send input file info via ajax - by dzoniboj - 02-04-2015, 05:43 AM
RE: send input file info via ajax - by mwhitney - 02-04-2015, 08:34 AM
RE: send input file info via ajax - by dzoniboj - 02-04-2015, 08:56 AM
RE: send input file info via ajax - by mwhitney - 02-04-2015, 09:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB