【问题标题】:How do i get a value of select box in blueimp using php?如何使用 php 在 blueimp 中获取选择框的值?
【发布时间】:2016-11-17 07:48:17
【问题描述】:
<select name="select1">
<option>
Demo1
</option>
</select>

<select name="select2">
<option>
Demo1
</option>
</select>

我有两个选择框,我想将值发送到上传处理程序并插入到数据库中。

编辑:

我从两个输入字段插入值(它工作正常!),但我想获取选择框的值。

查询表单数据:

$(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;
}

【问题讨论】:

  • ?

标签: php jquery file-upload blueimp


【解决方案1】:
<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'];

【讨论】:

  • 我想在 blueimp jquery 文件上传管理器的上传处理程序中获取这个值。
【解决方案2】:
<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 个选择框。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-09-06
  • 1970-01-01
  • 1970-01-01
  • 2011-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多