gpt4 book ai didi

php - 移动设备发出的 HTML 表单必填字段

转载 作者:行者123 更新时间:2023-11-28 11:25:15 27 4
gpt4 key购买 nike

我正在寻求你们中一位专家的帮助。我在我的网站上发布了一个 HTML 表单,这个 html 表单包含必填字段,通过移动设备提交时不需要这些字段。因此,我不断收到移动用户的空白表格。请给我建议解决方案,或指出我可能遗漏的问题。

非常感谢!!!

html 形式:

    <form id="form2" action="../../tbs_services/tbs_facial/facial_athlone.php" method="post" name="form2">
<table width="auto">
<tr>
<td height="10" colspan="2"><p class="h_text">First Name:</p></td>
<td width="240"><input type="text" required class="textfield" id="firstname" name="firstname" size="40"></td>
<td colspan="2" align="left" valign="top"></td>
</tr>
<tr>
<td height="10" colspan="2"><p class="h_text">Last Name:</p></td>
<td><input type="text" required class="textfield2" id="lastname" name="lastname" size="40"></td>
<td colspan="2" align="left" valign="top"></td>
</tr>
<tr>
<td height="10" colspan="2"><p class="h_text">Email Address:</p></td>
<td><input type="email" required class="email" id="email" name="email" size="40"></td>
<td colspan="2" align="left" valign="top"></td>
</tr>
<tr>
<td height="10" colspan="2"><p class="h_text">Mobile No:</p></td>
<td><input type="tel" required class="tel" id="tel" name="tel" size="40"></td>
<td width="104">&nbsp;</td>
<td width="70">&nbsp;</td>
</tr>
<tr>
<td height="10" colspan="2"><p class="h_text">Preferred Time:</p></td>
<td><select name="select" style="width: 184px" id="preferredtime">
<option>Morning</option>
<option>Afternoon</option>
<option>Evening</option>
</select></td>
<td colspan="2" align="left" valign="top"></td>
</tr>
<tr>
<td height="10" colspan="2"><p class="h_text">Preferred Date:</p></td>
<td><input type="date" required value="dd-mm-yy" class="date" name="date" id="date" style="width: 183px"></td>
<td colspan="2" align="left" valign="top"></td>
</tr>
<tr>
<td height="10" colspan="2"><p class="h_text">What would you like to book?</p></td>
<td>&nbsp;</td>
<td colspan="2" align="left" valign="top"></td>
</tr>
<tr>
<td width="23" height="30"><input type="checkbox" name="checkbox1" value="YES" id="emfacial"></td>
<td width="233"><p class="h_text">Express Mini Facial</br>
15-30min - €15</p></td>
<td width="253">&nbsp;</p></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td width="50">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input id="submit_form2" type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>

这是用于邮寄提交的表单的 PHP 文件:

/* Email Description */
$emailSubject = 'Athlone Mini Facial Appointment Enquiry'; /*Email Subject!*/
$webMaster = '<-- my email address -->';

/* Data Variables */
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$select = $_POST['select'];
$date = $_POST['date'];
$checkbox1 = $_POST['checkbox1'];


$body = <<<EOD
Booking from (www.thebodyshop.ie)<br><br>
Hi Athlone store, you have received an appointment enquiry.<br>
Please contact customer below to confirm availability.
<br><br><br>
First name: $firstname <br>
Last name: $lastname <br>
Email address: $email <br>
Mobile no: $tel <br>
Preferred time: $select <br>
Preferred date: $date <br>
Express Mini Facial: $checkbox1 <br>

EOD;
$headers = "From: $firstname\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);


/* Results landing as HTML */
$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="3;URL=http://www.thebodyshop.ie/services.html">
<style type="text/css">

<!--

body {

background-color: rgba(46,186,237,.7);/*Stylesheet to the landing page!*/

font-family: Verdana, Arial, Helvetica, sans-serif;

font:normal 300%/1em "TBSactivist", Arial, Helvetica, sans-serif;

text-transform:uppercase;

color:white;

text-align: center;

text-decoration: none;

padding-top: 200px;

margin-left: auto;

margin-right: auto;

max-width: 100% !important;

height:auto;

}

-->

</style>
</head>
<div align="center">Thank you for your booking enquiry.<br><br>A staff member will be in touch within 72 hrs.</div>
</body>
</html>
EOD;
echo "$theResults";
?>

再次感谢!

最佳答案

理想情况下,您需要为您的字段包含某种服务器端验证。这也有助于确保使用过时浏览器的用户填写必填字段。

在你的 php 中有这样的东西:

session_start();

$errors = array();

if(!$firstname)
$errors['firstname'] = 'Please enter your first name';

if(!$lastname)
$errors['lastname'] = 'Please enter your first name';

等..

在构建电子邮件之前,您可以检查错误:

if(count($errors)) {
$_SESSION['data'] = $_POST;
$_SESSION['errors'] = $errors;
header('Location: BACK TO YOUR FORM');
}

从这里,您拥有他们在 $_SESSION['data'] 变量中输入的数据,因此您可以填写他们拥有的数据,然后显示缺失字段的错误。

关于php - 移动设备发出的 HTML 表单必填字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21379245/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com