【问题标题】:Using Codeigniter, how can I tell if a form was submitted with jquery submit()使用 Codeigniter,如何判断表单是否使用 jquery submit() 提交
【发布时间】:2013-06-02 05:35:05
【问题描述】:

所以我使用 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'),我可以使用带有value 的按钮来检查表单是否已提交。我有var_dumped $this->input->post(),但它只返回输入字段的值。

【问题讨论】:

  • 要获得image的详细信息,您必须var_dump($_FILES)
  • @dianuj - 正是我正在寻找的。我可以说else if($_FILES['userfile']['name'])如果你回答我会把你标记为正确答案。
  • 查看我的更新答案,这将帮助您使用 CI 的库上传文件

标签: php jquery codeigniter


【解决方案1】:

正如上面的评论,我被要求发表我的评论作为答案,所以你去吧

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.

 }

这里是upload代码看看

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多