使用Codeigniter,如何判断一个表单是否是通过jquery submit()提交的?

6

我使用PHP编写了一个向导,其中一个表单需要用户上传图片。

我已经完成了所有内容,唯一的问题是在我的if语句中,我必须能够判断表单是否使用jquery的submit()方法提交。

以下是使用jquery在用户选择图片后提交表单的代码。

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

这是我的if语句的样子。

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.

}

我已经知道的:

使用$this->input->post('back'),我可以检查表单是否使用值为BACK的按钮提交。我已经var_dumped $this->input->post(),但它只返回输入字段的值。


1
要获取image的详细信息,您需要使用var_dump($_FILES) - M Khalid Junaid
@dianuj - 正是我正在寻找的。我能够说 else if($_FILES['userfile']['name']) 如果你回答,我会将你标记为正确答案。 - Kolby
请查看我的更新答案,它将帮助您使用CI库上传文件。 - M Khalid Junaid
1个回答

5

如上评论所述,我被要求将我的评论发布为答案,因此在这里提供给您:

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.

 }

这里是上传代码,请看一下:

   $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();

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接