简体   繁体   English

Bootstrap Dual Listbox发送

[英]Bootstrap Dual Listbox send

I'm using Bootstrap Dual Listbox to select multiple data and to show the user how many persons will be in a oficial list and who won't. 我正在使用Bootstrap Dual Listbox选择多个数据,并向用户显示正式列表中将有多少人,而不会。 You can see an example on this page: http://www.virtuosoft.eu/code/bootstrap-duallistbox/ 您可以在此页面上看到一个示例: http : //www.virtuosoft.eu/code/bootstrap-duallistbox/

The point is that, even though it works, I would like to know How do I know which box has the selected items and send them through POST using PHP, because the only "select" tag that you can see in HTML is the only one with all the options that you want to select, and when you are moving the data side to side it creates to containers dynamically call box1 and box2. 关键是,即使它可以工作,我也想知道我如何知道哪个盒子中有选定的项目,并使用PHP通过POST将其发送出去,因为您可以在HTML中看到的唯一“ select”标签是唯一的带有要选择的所有选项,并且在将数据左右移动时,它会动态创建到容器的容器,分别调用box1和box2。

The code it is almost the same of this link, 'cause I couldn't write down the code here,don't know why it didn't display all the code (new one): Bootstrap Dual Listbox : How to Limit Selected Option , but is not the question that I was looking for. 此链接的代码几乎相同,因为我无法在此处写下代码,不知道为什么它不显示所有代码(新代码): Bootstrap Dual Listbox:如何限制所选选项 ,但这不是我一直在寻找的问题。

Hope you understand my point!! 希望你理解我的观点!

Thank you very much! 非常感谢你!

My view: 我的观点:

{!! Form::open(['class'=>'form-horizontal','role'=>'form']) !!}
    <select multiple="multiple" size="10" name="facturas[]" id="selectfacturas">
        @foreach($facturas as $factura)
            <option value="{{ $factura->id }}"{{ ( $factura->ordendepago_id==$op->id ? ' selected="selected"':'') }}>{{ $factura->descripcionLinda() }}</option>
        @endforeach
    </select>
    <script>
        var demo2 = $('#selectfacturas').bootstrapDualListbox({
          nonSelectedListLabel: 'Comprobantes disponibles',
          selectedListLabel: 'Comprobantes imputados a esta orden',
          preserveSelectionOnMove: 'moved',
          moveOnSelect: false,
          showFilterInputs: false,
        });
    </script>
    {!!Form::submit( 'Siguiente',array('class'=>'btn btn-primary','id'=>'btn-submit'))!!}
    {!!Form::close()!!}   

Then, in my controller: 然后,在我的控制器中:

public function selefacturasPost( $id ) {
    dd( \Input::All()  );

It returns an Array! 它返回一个数组!

    array:2 [▼
  "_token" => "YTlypLsDjO37GGTAHXcKcKfho1vKYx5c0xgDN1cM"
  "facturas" => array:2 [▶]
]

Here is my solution: 这是我的解决方案:

 <-- HTML: --> <form action="your_php_file.php" method="post" id="your-dual-listbox-form"> <select multiple="multiple" size="10" name="duallistbox" id="initializeDuallistbox"> <option value="option1">Option 1</option> <option value="option2">Option 2</option> <option value="option3" selected="selected">Option 3</option> ... <option value="option20" selected="selected">Option 20</option> </select> <input type="hidden" name="DataFromRightSideList" value="null" id="setState"> <button type="submit" class="btn btn-primary">Save</button> </form> <-- jQuery: --> <script type="text/javascript"> $('#your-dual-listbox-form').submit(function() { var formData = $('[name="duallistbox"]').val(); //this will get as a string values from the right side Your dual listbox $(function () { $('#setState').val(formData); //this will change value of input id="setState" }); $( '#your-dual-listbox-form' ).submit(); //and here submit your form return false; }); </script> <-- PHP: --> <?php echo $_POST['DataFromRightSideList']; //it will print something like "option 3, ..., option20" ?> 

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

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