16

以下 Jade 表单模板有什么错误?我无法让它提交值。

 div
   form(action='/signup',method='post')
     div(data-role='fieldcontain')
       fieldset(data-role='controlgroup')
         label(for='email') email
         input(id='email',type='text',value='',placeholder='@')
     div#passworddiv(data-role='fieldcontain')
       fieldset(data-role='controlgroup
         label(for='password') password
         input(id='password',type='password',value='',placeholder='')
     div(id='hiddendiv',data-role='fieldcontain')
       fieldset(data-role='controlgroup')
         label(for='hidden_password') password
         input(id='hidden_password',type='text',value='',placeholder='')
     div(data-role='fieldcontain')
       fieldset(data-type='vertical',    data-role='controlgroup') 
         label(for='showpass') show password
         input(id='showpass',type='checkbox')
     div(data-role='fieldcontain')   
       input(type='submit',value='Sign Up',data-transition='fade', data-theme='c')  
4

1 回答 1

40

问题是因为您没有给任何输入字段命名。

app.post('/signup', function(req,res){
  console.log(req.body);
})

回报: {}

如果您将表单编辑为以下内容:

 div
  form(action='/signup',method='post')
    div(data-role='fieldcontain')
      fieldset(data-role='controlgroup')
        label(for='email') email
           input(id='email',type='text',value='',placeholder='@',name='email')
    div#passworddiv(data-role='fieldcontain')
      fieldset(data-role='controlgroup')
        label(for='password') password
           input(id='password',type='password',value='',placeholder='',name='password')
    div(id='hiddendiv',data-role='fieldcontain')
      fieldset(data-role='controlgroup')
        label(for='hidden_password') password
           input(id='hidden_password',type='text',value='',placeholder='',name='password2')
    div(data-role='fieldcontain')
      fieldset(data-type='vertical', data-role='controlgroup')                                           
       label(for='showpass') show password
       input(id='showpass',type='checkbox')
    div(data-role='fieldcontain')   
      input(type='submit',value='Sign Up',data-transition='fade', data-theme='c')

输入一些数据后,

app.post('/signup', function(req,res){
  console.log(req.body);
})

返回:

{ email: 'testing@fake.com',
  password: 'asdf',
  password2: 'asdf' }
于 2012-04-14T07:51:11.007 回答