<select name="select1">
<option>
Demo1
</option>
</select>
<select name="select2">
<option>
Demo1
</option>
</select>
我有两个选择框,我想将值发送到uploadhandler并插入数据库。如何获得blueimp中使用php的选择框的值?
编辑:
我插入从两个输入字段(其工作正常!)的价值,但我希望获取选择框的值。
Jquery的表单数据:
$(function() {
$('#fileupload').fileupload({
dataType: 'json',
add: function (e, data) {
data.context = $('<button class="btn btn-primary"/><br/><br/>').text('Upload')
.appendTo($(".container"))
.click(function() {
data.context = $('<p/>').text('Uploading...').replaceAll($(this));
data.submit();
});
},
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<li class="list-group-item"/>').text(file.name).appendTo($(".container"));
});
data.context.text('Upload finished.');
}
}).bind('fileuploadsubmit', function (e, data) {
data.formData = {
'title': $('[name=title\\[\\]]').val(),
'description': $('[name=description\\[\\]]').val()
};
});
});
和输入字段。
<label class="title">
<span>Title:</span><br>
<input name="title[]" class="form-control">
</label>
<label class="description">
<span>Description:</span><br>
<input name="description[]" class="form-control">
</label>
这就是blueimp中的UploadHandler.php如何插入数据。
protected function handle_form_data($file, $index) {
$file->title = $_REQUEST['title'];
$file->description = $_REQUEST['description'];
}
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = parent::handle_file_upload(
$uploaded_file, $name, $size, $type, $error, $index, $content_range
);
if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`name`, `size`, `type`, `title`, `description`)'
.' VALUES (?, ?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
'sisss',
$file->name,
$file->size,
$file->type,
$file->title,
$file->description
);
$query->execute();
$file->id = $this->db->insert_id;
}
return $file;
}
? – Mitch