简体   繁体   English

如何从Bootstrap的下拉菜单向PHP发送值

[英]How to send value from dropdown menu of bootstrap to php

i have create searching bar with filter button that can search between Teacher and Student name. 我用过滤器按钮创建了搜索栏,可以在教师和学生姓名之间进行搜索。 First i can search to my database with fix to student but when i try to use filter button nothing send value from dropdown button So this is my poor code please come and help me 首先,我可以搜索到学生修复的数据库,但是当我尝试使用过滤器按钮时,没有任何内容从下拉按钮发送值,因此这是我可怜的代码,请过来帮助我

HTML: HTML:

<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
    <div class="input-group">
        <div class="input-group-btn search-panel">
            <button name="filter" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#" id="dropdownMenu1">
                <span class="selection pull-left">Select an option</span></button>
            <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1" style="box-shadow:0px 6px 12px rgba(0, 0, 0, 0.176)">
                <li><a href="#Teacher" class="" data-value="Teacher"><span>Teacher</span></a></li>
                <li><a href="#Student" class="" data-value="Student"><span>Student</span></a></li>
                <li class="divider"></li>
                <li><a href="#all">All</a></li>
            </ul>
        </div>
        <!-- <input type="hidden" name="search_param" value="all" id="search_param">          -->
        <input name="txtSearch" type="text" class="form-control" id="txtSearch" placeholder="Search term..."
            value="<?php echo $wordSearch; ?>">
            <span class="input-group-btn">
            <button id="btnSearch" class="btn btn-primary" type="submit">
                <span class="glyphicon glyphicon-search"></span></button>
            </span>
    </div>
</form>

and this is my JS 这是我的JS

<script type="text/javascript">
  $(".dropdown-menu").on('click', 'li a', function(){
    var selText = $(this).children("span").html();

   $(this).parent('li').siblings().removeClass('active');
      $('#vl').val($(this).attr('data-value'));
    $(this).parents('.input-group-btn').find('.selection').html(selText);
    $(this).parents('li').addClass("active");
  });

</script>

I have no idea about PHP PS. 我对PHP PS一无所知。 Everything are under the same page (pls see attached picture below) http://upic.me/i/hg/ssssss.jpg 一切都在同一页下(请参见下面的图片) http://upic.me/i/hg/ssssss.jpg

A link is not a form element. 链接不是表单元素。 You need to tell a form field (which will send the value - compared to a link) about the value. 您需要告诉表单字段(该表单字段将发送值-与链接相比)有关该值的信息。 You are actually already doing this in your javascript with this line: 您实际上已经在JavaScript中使用以下代码行了:

$('#vl').val($(this).attr('data-value'));

Now you just need to create the corresponding form field (with attribute id="vl") in your form. 现在,您只需要在表单中创建相应的表单字段(属性id =“ vl”)即可。 In this example use the "hidden" form field like this. 在此示例中,使用“隐藏”表单字段,如下所示。 Just add this somewhere between the tags: 只需将其添加到标签之间:

<input type="hidden" id="vl" name="vl" value="">

And then you can get the value in PHP with: 然后,您可以通过以下方式获得PHP的价值:

$_POST['vl']

If you are looking at posting data to the backend for a search you either need a ajax post to do it asyc (something like jquery ajax method) docs here 如果您正在寻找将数据发布到后端进行搜索的方法,则您需要ajax发布才能将其进行asyc(类似于jquery ajax方法) 文档

if you are wanting to use a form you'll need to read up on html forms heres the MDN docs before you get started on the php side of things 如果您想使用表格,则需要先阅读html表格, 这里是MDN文档,然后再开始使用php方面的东西

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

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