2016-11-17 26 views
1
<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; 
} 
+0

? – Mitch

回答

0
<form method="POST"> 
<select name="select1"> 
<option value="val1"> 
Demo1 
</option> 
</select> 

<select name="select2"> 
<option value="value2"> 
Demo1 
</option> 
</select> 
<input type="submit" value="Submit"> 
</form> 
<?php 
echo $_POST['select1']; 
echo $_POST['select2']; 
+0

我想在blueimp jquery文件上传管理器的uploadhandler中获取这个值。 –

0
<form method="POST"> 
    <input type="hidden" name="x" value="true"> 
    <select name="select1"> 
     <option value="value1"> 
      Demo1 
     </option> 
    </select> 

    <select name="select2"> 
     <option value="value2"> 
      Demo1 
     </option> 
    </select> 
    <input type="submit" value="Submit"> 
</form> 
<?php 
    if(isset($_POST['x'])){ 
     echo $_POST['select1']; 
     echo $_POST['select2']; 
    } 
?> 

基本上,当你按下提交按钮,它会检查是否张贴名为 “X” 的隐藏字段。如果发布,则回显2个选择框。

+0

,我明白了。但我想要的值,以及uploadhandler将如何使用此值。检查这个https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration –

相关问题