作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个当前可用的表单,但想将 php 代码添加到“post”文件,因此需要 html 表单中的某些字段,否则会显示一条消息。
这是我目前的 html 代码。
<form action="contact.php" method="post">
<input type="text" class="main" name="cf_name" value="Name (Required)" size="31" />
<br />
<br />
<input type="text" class="main" name="cf_company" value="Company" size="31" />
<br />
<br />
<input type="text" class="main" name="cf_phone" value="Phone (Required)" size="31" />
<br />
<br />
<input type="text" class="main" name="cf_email" value="Email (Required)" size="31" />
<br />
<br />
<textarea type="text" name="cf_text0" cols="34" rows="3" class="main">Message</textarea>
<br />
<input type="image" src="images/send.jpg" height="16" width="41" border="0"
alt="Submit Form" />
</form>
这是我的 php 代码
<?php
$field_name = $_POST['cf_name'];
$field_company = $_POST['cf_company'];
$field_phone = $_POST['cf_phone'];
$field_email = $_POST['cf_email'];
$field_message = array($_POST["cf_text0"],);
$mail_to = 'callum@colmandesigns.co.nz';
$subject = 'A & J Print - Contact Form '.$field_name;
$field_message="From: {$field_name}
Company: {$field_company}
Phone: {$field_phone}
Email: {$field_email}
Message: {$field_message[0]}";
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $field_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to craig@colmandesigns.co.nz');
window.location = 'index.html';
</script>
<?php
}
?>
我想要填写姓名、电话和电子邮件字段。
谢谢,卡勒姆
最佳答案
在 HTML 中,您可以只放置“required”属性来使输入标签成为必需的!例如
<input type="text" id="someId" name="IP" placeholder="IP" required tabindex="1">
或
<input type="text" id="someId" name="IP" placeholder="IP" required="true" tabindex="1">
但是考虑一下,IE 和 Safari 直到现在才支持这个标签!
关于php - 带有必填字段的 html 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10219557/
我是一名优秀的程序员,十分优秀!