因此,我使用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的value
的按钮提交了表单。我有var_dumped $this->input->post()
,但它只返回输入字段的值。
就像上面的评论一样,我被要求发表我的评论作为答案,所以这里
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();
}