我正在尝试在我的网站上获取 optin 表单以不发送空字段。
我还在表单字段中预定义了文本(例如“在此处输入您的姓名”),单击时会消失。我也不希望表单发送预定义的文本数据。
用 PHP 解决这个问题的最佳方法是什么?
HTML:
<div class="form">
<h2>Get An Appointment: <font size="3"><font color="#6E5769">Fill in the form below now, and I'll call you to setup your next dental appointment...</font></font></h2>
<p id="feedback"><?php echo $feedback; ?></p>
<form action="contact.php" method="post"/>
<p class="name">
<input type="text" name="name" id="name" style="text-align:center;" onClick="this.value='';" value="Enter your name"/>
PHP:
<?php
$to = 'test@mywebsite.com'; $subject = 'New Patient';
$name = $_POST['name']; $phone = $_POST['phone'];
$body = <<<EMAIL
Hi, my name is $name, and phone number is $phone.
EMAIL;
$header = 'From: test@mywebsite.com';
if($_POST){ if($name != '' && $phone != ''){ mail($to, $subject, $body, $header); }else{ $feedback = 'Fill out all the fields'; } } ?>