Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Codeigniter, how can I tell if a form was submitted with jquery submit()

So I've built a wizard using php, and one of the forms asks for the user to upload an image.

I've built everything out already, the only problem is I have to be able to say, in one of my if-statements, if the form was submitted using jquery's submit() method.

So here is the code that submit's the form in jquery after the user has selected an image.

var initUpload = function(){
    $('.filebutton').change(function(e){
        $("form").submit();
    });
};

And this is how my if statement looks.

if($this->input->post('back')){

   //Tells me that the user clicked on the back button, and to go back 1 step in the wizard.    

}else if(???){

   //This is where I would like to say: if form was submitted with jquery.      

}else{

   //Else the user just clicked "next" and to continue normally.

}

What I already know:

Using $this->input->post('back') I can check if the form was submitted using a button with the value of BACK. I've var_dumped $this->input->post() but it only returns the values of the input field.

like image 229
Kolby Avatar asked Oct 04 '22 23:10

Kolby


1 Answers

As in above comment i was requested to post my comment as answer so here you go

if($this->input->post('back')){

//Tells me that the user clicked on the back button, and to go back 1 step in the wizard.    

}else if($_FILES['your_image_filed_name']){

//This is where I would like to say: if form was submitted with jquery.  
//you can use codeigniter's built in Upload libraray which v easy      

}else{

 //Else the user just clicked "next" and to continue normally.

 }

Here is the upload code have a look at

   $config_logo_image = array(
    'allowed_types' => 'jpg|jpeg|gif|png',
    'upload_path' => UPLOAD_PATH,//root path for image
    'max_size' => 2000,
    );
$this->load->library('upload', $config_logo_image );                    
if($this->upload->do_upload('your_image_filed_name')){

$logo_image_data = $this->upload->data();

}
like image 107
M Khalid Junaid Avatar answered Oct 13 '22 10:10

M Khalid Junaid