2016-06-13 70 views
0

我沒有像我想的那樣從「request.vars」或「request.post_vars」中的表單提交中獲取值。如何從Web2Py中的表單提交中獲取值

這裏是我的HTML表單:

{{extend 'layout.html'}} 
{{=message}} 
<form id="LoginForm" name="FormLogin" action="{{URL()}}" method="post"> 
<div class="container"> 
     <div class="row"> 
     <div class="col-md-offset-5 col-md-3 col-sm-6"> 
     <div class="form-login"> 
      <h4>{{=T("Welcome")}}</h4> 
      <input type="text" id="UserName" class="form-control input-sm chat-input" placeholder="{{=T("username")}}" /> 
      </br> 
      <input type="text" id="UserPassword" class="form-control input-sm chat-input" placeholder="{{=T("password")}}" /> 
      </br> 
      <div class="wrapper"> 
       <span class="group-btn">  
        <button type="submit" class="btn btn-primary btn-md">{{=T("login")}} <i class="fa fa-sign-in"></i></button> 
       </span> 
       <span class="group-btn" style="float:right;"> 
        <a href="{{=URL("prov_login", "register")}}" class="btn btn-success btn-md">{{=T("Register")}}</a> 
       </span> 
      </div> 
     </div> 

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

我的控制器看起來是這樣的:

def index(): 
if request.vars>0: 
    out_message = "Registration request received " 
else: 
    out_message = "no post" 

return dict(message=out_message) 

我缺少什麼?爲什麼我沒有獲得輸入值?

回答

1

查看代碼:

{{extend 'layout.html'}} 
{{=message}} 
<form> 
    <div class="container"> 
     <div class="row"> 
      <div class="col-md-offset-5 col-md-3 col-sm-6"> 
       <div class="form-login"> 
        <h4>{{=T("Welcome")}}</h4> 
        <input type="text" id="UserName" name="username" class="form-control input-sm chat-input" placeholder="{{=T("username")}}" /> 
        </br> 
        <input type="text" id="UserPassword" name="password" class="form-control input-sm chat-input" placeholder="{{=T("password")}}" /> 
        </br> 
        <div class="wrapper"> 
         <span class="group-btn">  
         <button type="submit" class="btn btn-primary btn-md">{{=T("login")}} <i class="fa fa-sign-in"></i></button> 
         </span> 
         <span class="group-btn" style="float:right;"> 
          <a href="{{=URL("prov_login", "register")}}" class="btn btn-success btn-md">{{=T("Register")}}</a> 
         </span> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</form> 

控制器代碼:

def index(): 
    if request.vars>0: 
     #out_message = "Registration request received" 
# you can write this then you see all vars return after form submission 
     out_message = request.vars 
    else: 
     out_message = "no post" 
    return dict(message=out_message) 
+0

在輸入標籤,你也可以指定name屬性,那麼您提交表格後得到瓦爾數據。 –

+0

設置名稱屬性。 –

+0

那麼,你在表單提交後得到值還是不? –

相關問題