提交表单时缺少字段 [英] Missing fields when submitting form

查看:148
本文介绍了提交表单时缺少字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



提交以下表格,我并不是这样,因为当你知道这件事时它非常明显,

 < form action =form.phpmethod =post> 
< label for =firstName>名字:< / label>
< input type =textid =firstName/>
< label for =lastName>姓氏:< / label>
< input type =textid =lastName/>
< label for =address>地址:< / label>
< input type =textid =address/>
< label for =age>年龄:< / label>
< input type =textid =age/>
<按钮类型=提交>提交!< /按钮>
< / form>


解决方案

那么答案很直接:我没有指定名称属性。

如果没有名称属性,浏览器无法发送任何内容。所以这里是我的工作表单:

 < form action =form.phpmethod =post> 
< label for =firstName>名字:< / label>
< input type =textid =firstNamename =firstName/>
< label for =lastName>姓氏:< / label>
< input type =textid =lastNamename =lastName/>
< label for =address>地址:< / label>
< input type =textid =addressname =address/>
< label for =age>年龄:< / label>
< input type =textid =agename =age/>
<按钮类型=提交>提交!< /按钮>
< / form>


I'm sharing this one because it's so obvious when you know it, but makes you bang your head when not!

Submitting the following form, I wasn't getting any of my fields:

<form action="form.php" method="post">
    <label for="firstName">First name: </label>
    <input type="text" id="firstName" />
    <label for="lastName">Last name: </label>
    <input type="text" id="lastName" />
    <label for="address">Address: </label>
    <input type="text" id="address" />
    <label for="age">Age: </label>
    <input type="text" id="age" />
    <button type="submit">Submit!</button>
</form>

解决方案

Well the answer was quite straight: I didn't specify a name attribute.

Without the name attribute, it's impossible for the browser to send anything. So here's my working form:

<form action="form.php" method="post">
    <label for="firstName">First name: </label>
    <input type="text" id="firstName" name="firstName" />
    <label for="lastName">Last name: </label>
    <input type="text" id="lastName" name="lastName" />
    <label for="address">Address: </label>
    <input type="text" id="address" name="address" />
    <label for="age">Age: </label>
    <input type="text" id="age" name="age" />
    <button type="submit">Submit!</button>
</form>

这篇关于提交表单时缺少字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆