嘿所有,我的网站上有一个HTML表单,目前只使用文本框和提交按钮发送到.php文件,然后发送到我的电子邮件。我正在尝试用下拉(选择,选项)菜单替换其中一个文本框。
这是我的HTML表单:
<form id="ajax-contact-form" action="javascript:alert('success!');">
<label>Name:*</label><INPUT class="textbox" type="text" name="name" value=""><br />
<label>E-Mail:*</label><INPUT class="textbox" type="text" name="email" value=""><br />
<label>Number Desired:*</label><INPUT class="textbox" type="text" name="numberdesired" value=""><br />
<label>Message:</label><TEXTAREA class="textbox" NAME="message" ROWS="7" COLS="40"></TEXTAREA><br /><br />
<INPUT class="textbox" type="hidden" name="subject" value="Form Submission" >
<label>Human Verification:*<br />
<?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label><input type="text" name="captcha" id="captcha" /><br />
<label> </label><INPUT class="button" type="submit" name="submit" value="Send Message">
</form>
这是发送给它的php文件:
<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/
include 'config.php';
session_name("fancyform"); /* starting the session */
session_start();
$post = (!empty($_POST)) ? true : false;
if ($post) {
include 'functions.php';
$email = trim($_POST['email']);
$name = stripslashes($_POST['name']);
$subject = stripslashes($_POST['subject']);
$captcha = stripslashes($_POST['captcha']);
$numberdesired = stripslashes($_POST['numberdesired']);
$message = stripslashes($_POST['message']);
$error = '';
// Check name
if (!$name) {
$error .= 'Please enter your name.<br />';
}
// Check email
if (!$email) {
$error .= 'Please enter an e-mail address.<br />';
}
if ($email && !ValidateEmail($email)) {
$error .= 'Please enter a valid e-mail address.<br />';
}
if (!$numberdesired) {
$error .= 'Please enter the number desired.<br />';
}
if ((int)$_POST['captcha'] != $_SESSION['expect'])
$error .= 'Wrong verification number.';
//Send the Name, Email, and Message in a formated version.
$email_message = "The following message was sent to you from....\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Gamertag: ".clean_string($name)."\n";
$email_message .= "Credits Desired: ".clean_string($numberdesired)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
if (!$error) {
$mail = mail(WEBMASTER_EMAIL, $subject, $email_message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if ($mail) {
echo 'OK';
}
}
else {
echo '<div class="notification_error">'.$error.'</div>';
}
}
?>
现在我对PHP很新。我不认为'stripslashes'会读取下拉菜单。还有其他我可以使用的东西吗?
答案 0 :(得分:3)
当前菜单选择的值将在$ _POST变量中返回。
文本来自下拉菜单而不是文本框这一事实对您的php程序没有任何影响。
唯一不同的“输入”字段是“复选框”。如果没有选中任何选项,则根本不会返回$ _POST变量。