表单提交按钮在引导模式窗口中不起作用

时间:2015-07-28 20:07:11

标签: forms twitter-bootstrap post submit

我一直在努力使这项工作,但提交按钮根本不起作用。

我使用的bootstrap模态窗口是:

<div class="modal fade" id="search" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-header">
            <a class="close" data-dismiss="modal">×</a>
            <h4><span class="fa fa-search"></span> Search Anything...</h4>
        </div>          
        <form name='searchdata' action="webarch/search.php" method="post" id="form1">
        <div class="modal-body">
                <div class="input-with-icon success-control"> 
                    <input type="text" class="form-control" id="form1Amount" name="searchvalue" placeholder="Search in users or #hashtags"><br/>
                    <button type="submit" name='user_search' form="form1" id="user_search" value='user' class="btn btn-danger btn-cons"><i class="fa fa-user"></i> User</button>
                    <button type="submit" name='tag_search' form="form1" value='tag' class="btn btn-default"><i class="fa fa-tag"></i> Tags</button>

                </div>  
        </div>          
        </form> 
    </div>
</div>

每当我点击提交按钮时,没有任何反应,表单也不会发布值。 让我知道如何使这项工作。

3 个答案:

答案 0 :(得分:12)

使用javascript尝试此操作。它对我有用:

 <form name='searchdata' id="search_form" action="search.php" method="get">
                <div class="input-with-icon success-control">  
                    <input type="text" class="form-control" id="form1Amount"     name="searchvalue" placeholder="Search in users or #hashtags"><br/>
                </div>  
                <button onclick="form_submit()" name='user_search' value='user' class="btn btn-danger"><i class="fa fa-user"></i> User</button>
                <button onclick="form_submit()" name='tag_search' value='tag' class="btn btn-default"><i class="fa fa-tag"></i> Tags</button>           
        </form> 

  <script type="text/javascript">
  function form_submit() {
    document.getElementById("search_form").submit();
   }    
  </script>

答案 1 :(得分:3)

“提交”按钮不在表单中。将form =“ modal-details”放置在按钮上,它是表单ID。提交按钮上不应具有data-dismiss =“ modal”,这是用于关闭模式框的引导处理程序。它对我有用。

<div class="modal fade" id="filterModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Client Filter</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form asp-action="Details" asp-controller="Client" method="get" id="modal-details">
                    <div class="form-group">
                        <label for="recipient-name" class="col-form-label">Branch:</label>
                        <select asp-for="NetworkUnitId" class="custom-select form-control">
                            <option value="0">All</option>
                            @foreach (var client in classifierService.GetClients())
                            {
                                <option value="@client.Id">@client.Name</option>
                            }
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary" form="modal-details">Search</button>
            </div>
        </div>
    </div>
</div>

答案 2 :(得分:0)

您在这里没有提到模态内容。我认为这就是为什么您会得到错误的原因。

<button type="button" class="btn btn-primary" data-target="#search" data-toggle="modal" name="button">modal</button>
  <div class="modal fade" id="search" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

      <div class="modal-header">
        <div class="modal-title">
          <a class="close" data-dismiss="modal">&times;</a>
          <h4><span class="fa fa-search"></span> Search Anything...</h4>
        </div>
      </div>

    <form name='searchdata' action="webarch/search.php" method="post" id="form1">
      <div class="modal-body">
            <form class="frm-group" action="index.html" method="post">
              <div class="modal-content">
                  <input type="text" name="" value="">
                  <button type="submit" name='user_search' form="form1" id="user_search" value='user' class="btn btn-danger btn-cons"><i class="fa fa-user"></i> User</button>
                  <button type="submit" name='tag_search' form="form1" value='tag' class="btn btn-default"><i class="fa fa-tag"></i> Tags</button>
              </div>
            </form>
        </div>
    </div>