我正在用php制作一个就业表格,其中包含多个字段,如文本,文件,选择和文本区域。当有人提交表单时,我在电子邮件中收到文本和文本区域字段,但没有选定的值和文件(附件)。
我的php代码是:
if(trim($_POST['FindElance']) || ($_POST['FindGoogle']) || ($_POST['Findsarch']) || ($_POST['FindAdvertisement']) || ($_POST['FindOther']) === '') {
$FwhereError = 'Please tell where you find us.';
$FwhereError = true;
} else {
$Fwhere = trim($_POST['Fwhere']);
}
这是电子邮件正文变量,它将向我的电子邮件发送值:
$body = "
Where you find us : $Fwhere
";
这是HTML的代码,我正在尝试在其中获得验证等:
<div class="clear">How did you find us? : <span class="error">*</span><br></div>
<label class="overyalk" for="areaofinterest"></label>
<select id="wherefrom" class="era-select" name="howufindus" onclick="showhere()">
<option value="FindElance">Elance</option>
<option value="FindGoogle">Google</option>
<option value="Findsarch">Search engin</option>
<option value="FindAdvertisement">Advertisment</option>
<option value="FindOther">Other</option>
</select>
</div>
我被困住了,不知道它将如何完成。这是我工作的在线表格
http://gaabc.us/employment-application-form/
您也可以下载我正在创建的文件。它都在一个文件中,它是主题内的Wordpress页面。
http://gaabc.us/wp-content/uploads/2013/10/template-employe.zip
你的问题不够清楚:(
无论如何,试试这个....
$body = "Where you find us : ". $Fwhere;
在本地
系统上尝试此代码作为起点
<?php
if($_POST) {
echo "<pre>";
print_r($_POST);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="test" method="post" action="" name="testform">
<select name="testselect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="file" name="testfiel" />
<input type="submit" value="submit" />
</form>
</body>
</html>
这将向您显示提交表单后获得的参数,也不要将上传的文件添加为扩展名,您需要使用 $_File 方法进行检查。
if(trim($_POST['howufindus']) == '') {
$FwhereError = 'Please tell where you find us.';
$FwhereError = true;
} else {
echo $Fwhere = trim($_POST['howufindus']);
}
这是
你想要的吗?
if(isset($_POST['Fwhere'])) {
$Fwhere = $_POST['Fwhere'];
}
根据您的 html 选择框,您将不会通过以下方式获得所选值:
<select id="wherefrom" class="era-select" name="howufindus" onclick="showhere()">
<option value="FindElance">Elance</option>
<option value="FindGoogle">Google</option>
<option value="Findsarch">Search engin</option>
<option value="FindAdvertisement">Advertisment</option>
<option value="FindOther">Other</option>
</select>
$_POST['FindElance'], $_POST['FindElance'], $_POST['Findsarch']...
您需要的是:
$_POST['howufindus'];
你的 php 会变成:
if(trim($_POST['howufindus'])) === '') {
$FwhereError = 'Please tell where you find us.';
$FwhereError = true;
} else {
$Fwhere = trim($_POST['Fwhere']);
}
干杯
你的 HTML 代码中没有 FindElance
、 FindGoogle
、 Fwhere
。
表单中的选择名称是"howufindus"。
所以你应该像这样$_POST
使用它:
if(!$_POST['howufindus']) {
$FwhereError = 'Please tell where you find us.';
$FwhereError = true;
} else {
$Fwhere = trim($_POST['howufindus']);
}
对于附件,您必须使用 $_FILES
.
希望这有帮助