Submit Jade form

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

What is the error with the following Jade form template? I can't get it to submit values.

 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')   

回答1:

The problem is because you haven't given any of the input fields a name.

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

Returns: {}

If you edit the form to the following:

 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') 

After entering some data,

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

returns:

{ email: 'testing@fake.com',   password: 'asdf',   password2: 'asdf' } 


文章来源: Submit Jade form
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!