我有一个简单的表单,包括输入类型文件和其他表单字段。我能够将输入类型文件数据发送到控制器,但是输入其他表单数据和输入类型文件存在问题
这是我到目前为止所做的事情 -
表格 -
<form method="post" id="theme_option_form" enctype="multipart-formdata">
Logo :<input type="file" name="image_file" id="image_file">
Logo Size :<input type="text" id="logo_size" class="form-control input-sm">
Heading Size :<input type="text" id="hding_size" class="form-control input-sm">
<input type="submit" name="upload" id="upload" value="Upload" class="btn btn-primary btn-sm">
</form>
Ajax代码 -
$('#theme_option_form').on("submit",function(e){
var hding_size=$('#hding_size').val();
var logo_size=$('#logo_size').val();
$.ajax({
url:base_url+'admin/theme_options_data',
method:'post',
data:new FormData(this),
contentType:false,
cache:false,
processData:false,
success:function(data){
alert(data);
}
});
});
控制器功能 -
public function theme_options_data()
{
if(isset($_FILES['image_file']['name']))
{
$this->load->helper('string');
$logo_name=random_string('alnum',5);
$config['upload_path']='./upload';
$config['allowed_types']='jpg|jpeg|png|gif';
$config['file_name']=$logo_name;
$this->load->library('upload',$config);
if(!$this->upload->do_upload('image_file'))
{
echo $this->upload->display_errors();
}
else
{
$data=$this->upload->data();
}
}
}
文件上传工作正常,但我只需要将表单数据(徽标大小,标题大小等)发送到控制器,稍后我必须将所有数据存储到数据库中。
请帮帮我
谢谢
答案 0 :(得分:0)
表格 ...填写字段名称。
<form method="post" id="theme_option_form" enctype="multipart-formdata">
Logo :<input type="file" name="image_file" id="image_file">
Logo Size :<input type="text" name="logo_size" id="logo_size" class="form-control input-sm">
Heading Size :<input type="text" name="hding_size" id="hding_size" class="form-control input-sm">
<input type="submit" name="upload" id="upload" value="Upload" class="btn btn-primary btn-sm">
<强>控制器强>
public function theme_options_data()
{
if(isset($_FILES['image_file']['name']))
{
$this->load->helper('string');
$logo_name=random_string('alnum',5);
$config['upload_path']='./upload';
$config['allowed_types']='jpg|jpeg|png|gif';
$config['file_name']=$logo_name;
$this->load->library('upload',$config);
if(!$this->upload->do_upload('image_file'))
{
echo $this->upload->display_errors();
}
else
{
$data=$this->upload->data();
}
}
$logo_size = $_POST['logo_size'];
$heading_size = $_POST['hding_size'];
}