这是一个简单的表单,它收集用户的信息并将该信息发送到指定的电子邮件地址。但每当我将这些信息提取到邮件&
时,就会在输入之间出现。喜欢
email=some%40gmail.com&password=asdf&password-repeat=asdf
如何删除此内容?请帮忙
这是我的HTML表单:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post" action="mailto:somebody@gmail.com">
<div class="container">
<h1>Register</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<label for="password-repeat"><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="password-repeat" required>
<hr>
<p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
<button type="submit" class="registerbtn">Register</button>
</div>
<div class="container signin">
<p>Already have an account? <a href="#">Sign in</a>.</p>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
有两种方法可以做到这一点:
1)将enctype="text/plain"
添加到您的<form>
标记中,例如:
<form method="post" enctype="text/plain" action="mailto:alice@example.com">
2)将formenctype="text/plain"
添加到您的<button>
标记中,例如:
<button type="submit" formenctype="text/plain" class="registerbtn">Register</button>
这两种方法都会产生如下的身体:
email=bob@example.com
password=asdf
password-repeat=asdf
这是必要的,因为表单的默认MIME类型是application/x-www-form-urlencoded
。您可以在Mozilla.org上阅读更多相关信息。我在下面引用了enctype
,但为两者提供了链接。
<强>是enctype 强>
当method属性的值为post时,enctype是用于将表单提交给服务器的MIME内容类型。可能的值有:
application/x-www-form-urlencoded
:如果未指定属性,则为默认值。multipart/form-data
:用于<input>
元素的值,其type属性设置为“file”。text/plain
(HTML5)此值可以被
<button>
或<input>
元素上的formenctype属性覆盖。
这是您的代码(带有演示电子邮件地址)作为enctype
的运行示例:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post" enctype="text/plain" action="mailto:alice@example.com">
<div class="container">
<h1>Register</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<label for="password-repeat"><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="password-repeat" required>
<hr>
<p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
<button type="submit" class="registerbtn">Register</button>
</div>
<div class="container signin">
<p>Already have an account? <a href="#">Sign in</a>.</p>
</div>
</form>
</body>
</html>