Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask: Not able to receive HTML form POST data

Here is my HTML

  <form class="form-horizontal" action="/" method="POST">
    <div class="control-group">
      <label class="control-label" for="email">Email</label>
      <div class="controls">
        <input type="text" id="email" placeholder="Email">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="password">Password</label>
      <div class="controls">
        <input type="password" id="password" placeholder="Password">
      </div>
    </div>
    <div class="control-group">
      <div class="controls">
        <button type="submit" class="btn">Sign In</button>
      </div>
    </div>
  </form>

When I submit form, on server I try to print it, I do

   def post(self):
        print 'data :', request.form

I get

data : ImmutableMultiDict([])

I also try

def post(self):
        print 'data :', request.json

I get

data : None

What exactly I am missing here

like image 280
daydreamer Avatar asked Apr 23 '13 03:04

daydreamer


1 Answers

None of your inputs have name attribute

Therefore, nothing sent.

        <input type="password" id="password" placeholder="Password">

should be:

        <input type="password" id="password" name="password" placeholder="Password">

ID is just for DOM

like image 87
Tigra Avatar answered Sep 20 '22 18:09

Tigra