2016-11-17 27 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 –

相關問題