在閱讀了這裏的許多帖子後,關於如何捕獲我的html表單中的Select值,我理解了原理,但我似乎無法在下面的代碼中完美地執行它。
$ selected_val未被追加。也許它是空的?我錯過了什麼?提前致謝。無法捕獲表單選擇值,php
期望的結果:
[email protected]爲A-用戶,
當前結果:
[email protected]是,
下面是如何我的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);
}
?>
哪裏是表格標籤 –
現在會發生什麼? – chris85
您的'