简体   繁体   English

从引导模式获取值,然后进程将值插入数据库

[英]Get values from bootstrap modal, process then insert value to database

I am using table where values are printed from database. 我正在使用从数据库打印值的表。 Then I make selections. 然后我做出选择。 After that I want to process those values together with values from bootstrap modal which are required to fill. 之后,我想要处理这些值以及bootstrap模态中需要填充的值。 Once I get all values, I need to store them into database. 获得所有值后,我需要将它们存储到数据库中。

Table store values from database: 来自数据库的表存储值:

<table id="table"  class="table table-bordered table-striped">
    <thead>
      <tr class="bg-red">
        <th>Id</th>
        <th>Material</th>
        <th>Quality</th>
        <th>Dimensions</th>
        <th>Colors</th>
        <th>Weight</th>    
        <th><center><i class="fa fa-shopping-cart"><center></th>
      </tr>
    </thead>
    <tbody>
    <?php while($r=$q->fetch()){ ?>
      <tr>
        <td class='data-id'><?='B-'. $r['Id']?> </td>
        <td> <?=$r['Material']?> </td>
        <td><?=$r['Quality']?></td>
        <td><?=$r['Dimensions']?></td>
        <td><?=$r['Colors']?></td>
        <td><?=$r['Weight']?></td>
        <td> <button class="addValues" name="code[]" value="<?='B-'. $r['Id']?>"><i class="fa fa-shopping-cart"></button></td>
      </tr>
    <?php } ?>
    </tbody>
</table>

Then I am using script make row selection and print values to another div (This section works) 然后我使用脚本make行选择和打印值到另一个div(本节适用)

<script>
    $(".addValues").click(function () {
        $('#selection').show();
            var $this = $(this),
            myCol = $this.closest("td"),
            myRow = myCol.closest("tr"),
            targetArea = $("#selection");

            var qte_input = (' <input type="text" name="quantity[]" placeholder="kg / m" size="10"/>');
              targetArea.prepend($("td.data-id", myRow).text() + qte_input +"<hr />"); 
          });
</script>

Output in div after row is selected (Multiple selections could be chosen) 选择div后的输出(可以选择多个选项)

B-15897 3000kg // B-15897 presents code 3000kg presents quantity. B-15897 3000kg // B-15897赠送代码3000kg赠品数量。 B-4589 500m B-4589 500米

Below those values I have submit button, which opens bootstrap modal. 在这些值下面,我有提交按钮,它会打开bootstrap模式。

<div class="col-xs-2">
    <div class="box box-danger">
        <h4>Selected: </h4><br/>
        <div id="selection">
            <!-- SELECTED VALUES  -->
            B-15897 3000kg
            B-4589  500m
        </div>
        <button class="btn btn-block bg-red btn-sm" data-toggle="modal" data-target="#myModal">Send request</button>
    </div>
</div>

Once I hit Send request it opens bootstrap modal: 一旦我点击发送请求,它就会打开bootstrap模式:

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" href="repromaterijali-script.php">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Offer request</h4>
      </div>
      <div class="modal-body">
        * Company name
        <input type"text" class="form-control" name="company"  required><br/>
        * Contact info
        <input type"text" class="form-control" name="contact" required><br/>
        * Adress
        <input type"text" class="form-control" name="address" required><br/>
        * Phone
        <input type"text" class="form-control" name="tel"required><br/>
        E-mail
        <input type"text" class="form-control" name="email" ><br/>
        Other
        <textarea type"text" class="form-control" name="other" ></textarea><br/>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" name="submit">Send</button>
      </div>
    </div>
  </div>
</div>

I want to pick all values from bootstrap modal and from div where selected values are, process them and insert in database via php. 我想从bootstrap模式中选择所有值,从div中选择值,处理它们并通过php插入数据库。 code and quantity will be an array because multiple values could be selected. 代码和数量将是一个数组,因为可以选择多个值。

Bootstrap modal and div where selected values are inside <form> . Bootstrap模态和div,其中所选值在<form> I am trying to get values by using script bellow but nothing happens: 我试图通过使用下面的脚本来获取值,但没有任何反应:

<script type="text/javascript">
    function get_values() {
        var x = document.getElementById("quantity").value;
        var y = document.getElementById("code").value;
        var arr = {barcode:x};
            $.ajax({ url: 'insert.php',
                 data: arr,
                 type: 'post',
                 success: function(output) {
                     document.getElementById("code").value = output;

                  }
        });
    }
</script>

I am looking for advice? 我在寻找建议? Any kind of help is very appreciated. 非常感谢任何形式的帮助。

Your modal isn't coded correctly on a couple of levels. 您的模态在几个级别上编码不正确。

First, the input elements do not have an id assigned. 首先, input元素没有分配id Normally one would get the value via the id . 通常会通过id获取值。 In a similar way you did here: 你在这里做的方式类似:

 var x = document.getElementById("quantity").value;

Also, while it has nothing to do with reading the values from the modal, from a Bootstrap perspective, your input form is not coded the way the Bootstrap CSS expects it to be coded. 此外,虽然它与从模式中读取值无关,但从Bootstrap角度来看,输入表单的编码方式与Bootstrap CSS期望编码的方式不同。

Here an example from the Bootstrap site: 这里是Bootstrap站点的一个例子:

 <div class="form-group">
     <label for="exampleInputPassword1">Password</label>
     <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  </div>

Notice each input is wrapped in a form-group . 请注意,每个输入都包含在一个form-group If you use this layout, you'll not need to use the <br> tag. 如果使用此布局,则无需使用<br>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM