表单仅提交一个输入字段而不是两个

时间:2013-10-25 23:40:01

标签: html django forms twitter-bootstrap

我正在使用Django和Bootstrap,我有一个页面,其中有两个输入和一个提交按钮:

   <div class="col-lg-5">
         <form id="search_form" align="right" action="/comparison/" class="form-inline" method ="get" role="form">
       <input id="navPersonSearch" class="input form-control" type="text" name="q1"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >

  </div> <!-- /.col -->
    <div class="col-lg-2">
    <button type="submit" class="btn btn-primary btn-lg btn-block">Compare</button>
   </div> <!-- ./col -->
   <div class="col-lg-5">
       <input id="navPersonSearch2" class="input form-control" type="text" name="q2"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >
  </form> 
  </div> <!-- /.col -->

但是,提交表单时,只会提交第一个值。例如,在第一个输入中如果你有“Tom”而第二个输入你有“Bob”,它将重定向到:

http://127.0.0.1:8000/comparison/?q2=Bob

当我想要提交两个值时。

2 个答案:

答案 0 :(得分:1)

HTML无效。移动<form>标记以完全包含开始和结束<div>。像这样:

<form id="search_form" align="right" action="/comparison/" class="form-inline" method ="get" role="form">  
    <div class="col-lg-5">  
        <input id="navPersonSearch" class="input form-control" type="text" name="q1"
               placeholder="Search for Actor/Actress" autocomplete="off" >
    </div> <!-- /.col -->
    <div class="col-lg-2">
        <button type="submit" class="btn btn-primary btn-lg btn-block">Compare</button>
     </div> <!-- ./col -->
     <div class="col-lg-5">
         <input id="navPersonSearch2" class="input form-control" type="text" name="q2"
                placeholder="Search for Actor/Actress" autocomplete="off" >
     </div> <!-- /.col -->
 </form> 

答案 1 :(得分:1)

做类似

的事情
<p><strong></p></strong>

很糟糕,导致html代码解释错误 你应该提前移动标签

<form id="search_form" align="right" action="/comparison/" class="form-inline" method ="get" role="form">
   <div class="col-lg-5">
       <input id="navPersonSearch" class="input form-control" type="text" name="q1"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >
   </div> <!-- /.col -->
   <div class="col-lg-2">
      <button type="submit" class="btn btn-primary btn-lg btn-block">Compare</button>
   </div> <!-- ./col -->
   <div class="col-lg-5">
       <input id="navPersonSearch2" class="input form-control" type="text" name="q2"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >
    </div> <!-- /.col -->
  </form>