在这里阅读了很多帖子之后,关于如何在我的html表单中捕获Select值,我理解了原理,但我似乎无法在下面的代码中完美地执行它。
$ selected_val未被追加。也许它是空的?我错过了什么?提前谢谢。
期望的结果:
test@test.com是 A-user ,
当前结果:
test@test.com是一个,
以下是我的HTML表单的外观:
<form method="POST" class="subscription-form form-inline id="subscribe" role="form">
<h4 class="subscription-success"><i class="icon_check"></i> Thank you for requesting... </h4>
<h4 class="subscription-error">Something Wrong!</h4>
<select name="usertype" class="form-control input-box">
<option selected value="A-user">I'm an A user</option>
<option value="B-user">I'm an B user</option>
<option value="C-user">I'm an C user</option>
</select>
<input type="email" name="email" id="subscriber-email" placeholder="Your Email" class="form-control input-box">
<button type="submit" name="submit" id="subscribe-button" class="btn btn-default standard-button">Submit</button>
</form>
这是我的php:
<?php
if ( isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
$selected_val = $_POST['usertype']; // Storing Selected Value In Variable
$e_mail = $_POST['email'] . " is a " . $selected_val . " ," . "\n";
file_put_contents('email-list.txt', $e_mail, FILE_APPEND | LOCK_EX);
}
?>
答案 0 :(得分:1)
您的表单缺少方法属性
发布方法应该在那里
<form action="your.php" method="post">
答案 1 :(得分:1)
$(document).ready(function()
{
$.getScript("vehicle_data.json", function()
{
// Pay attention. In this case, you work with carInfo
// variable because it has been executed as a script,
// but not loaded as a JSON file.
$.each(carInfo, function() {
$("ul").append("<li>Car ID: " + this[carInfo[0].carId]);
});
});
});
元素应具有<form>
属性,如
method
在您的PHP代码中注意,用户将点击提交按钮,然后检查
<form method="POST" class="subscription-form form-inline wow fadeInRight animated" data-wow-offset="10" data-wow-duration="1.5s" id="subscribe" role="form">