I have a very basic form. The form is being sent to the email, however it does not return any data, not sure what I am missing.
Here is my HTML code...
<form id="contact" action="process.php" />
<label for="name">Your name</label>
<input type="text" name="name" id="name" required>
<label for="size">Your Size</label>
<select id="size" name="size" required>
<option value="">Choose a Size</option>
<option value="s">S</option>
<option value="m">M </option>
<option value="l">L</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
...and here is my process.php file...
<?php
// Get Data
$name = strip_tags($_POST['name']);
$size = strip_tags($_POST['size']);
// Send Message
mail( "test@testing.com", "Email Contact",
"Name: $name\nSize: $size\n",
"From: Test Server" );
?>
This email will be received successfully, but will look like this...
Name:
Size:
It returns the labels but not the fields. Any help would be greatly appreciated.
请确保指定您的表单应为POST,以确保变量可以通过$_POST
:
<form id="contact" action="process.php" method="POST"/>
尝试:
<form id="contact" action="process.php" method="post" >
Unless you do not define form's sending method it is assumed as GET
as default.
Use method="POST"
<form id="contact" action="process.php" method="post">
...
</form>
In addition to this, you must check first if form is posted:
if(isset($_POST)) {
$name = strip_tags($_POST['name']);
$size = strip_tags($_POST['size']);
// Send Message
mail( "test@testing.com", "Email Contact", "Name: $name\nSize: $size\n", "From: Test Server" );
}
You may also use $_REQUEST
but it is more vulnerable than $_POST
. Because $_REQUEST
does not mind how data comes; accepts data both from $_GET
and $_POST
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.