我有一个 php 表单,可以将信息保存到我的数据库并在完成后发送电子邮件。但是它不会验证字段以查看它们是否为空,而是打印设置和未设置选项。关于为什么会发生这种情况的任何想法?在我向其添加表单字段验证之前,它运行良好。
作为旁注,由于需要 html 5 aria,它在 FF 和 Chrome 中有效,但在 IE 中无效
html
<form id="contact" name="contact" action="register1.php" method="post">
<label for='Cname'>Camper Name</label>
<input type="text" name="Cname" maxlength="50" value="" required aria-required=true />
<input type="hidden" id="action" name="action" value="submitform" />
<input type="submit" id="submit" name="submit" value="Continue to Camp Selction"/>
</form>
php
<?php
//include the connection file
require_once('connection.php');
//save the data on the DB and send the email
if(isset($_POST['action']) && $_POST['action'] == 'submitform')
{
//recieve the variables
$Cname = $_POST['Cname'];
//form validation (this is where it all breaks)
if (isset($Cname)) {
echo "This var is set so I will print.";
}
else {
echo '<script type="text/javascript">alert("please enter the required fields");</script>';
}
//save the data on the DB (this part works fine)