我的提交按钮有问题:它不起作用。它似乎适用于我以前的表格。我也在使用 Spry 验证。这是一个带有 PHP 的简单 HTML。我看不出我的错误在哪里(我刚刚开始学习 PHP)。我已经浏览了论坛和互联网,但我找不到我的问题的答案。我正在尝试通过电子邮件将基本表单发送给我,并选择在同一表单中上传文件。问题是来自表单格式还是 PHP 文件?以下是我拥有的代码: 这是位于<body><div id="content">...</div></body>
<p><form action="upload.php" name="form1" id="form1" method="post" enctype="multipart/form-data">
<fieldset><legend><em>Please fill this form</em></legend>
First Name: <span id="sprytextfield1">
<input type="text" name="firstname" id="firstname" required="required" />
<span class="textfieldRequiredMsg">Please enter your first name.</span></span><br/><br/>
Last Name: <span id="sprytextfield2">
<input type="text" name="lastname" id="lastname" />
<span class="textfieldRequiredMsg">Please enter your last name.</span></span><br/><br/>
Job Title: <span id="sprytextfield3">
<input type="text" name="title" id="title" />
<span class="textfieldRequiredMsg">Please enter your desired title.</span></span><br/><br/>
Address: <span id="sprytextfield4">
<input type="text" name="address" id="address" />
<span class="textfieldRequiredMsg">Please enter your address.</span></span><br/><br/>
Postal Code: <span id="sprytextfield5">
<input type="text" name="postal" id="postal" />
<span class="textfieldRequiredMsg">(i.e.: A0A 0A0)</span><span class="textfieldInvalidFormatMsg"></span></span><br/>
<br/>
City: <span id="sprytextfield6">
<input type="text" name="city" id="city" />
<span class="textfieldRequiredMsg">Please enter the name of your city.</span></span><br/><br/>
Province: <span id="spryselect1">
<select name="province" id="province">
<option value="ontario">Ontario</option>
<option value="quebec">Quebec</option>
<option value="britishcolumbia">British Columbia</option>
<option value="alberta">Alberta</option>
<option value="manitoba">Manitoba</option>
<option value="saskatchewan">Saskatchewan</option>
</select>
</span><br/><br/>
Phone Number: <span id="sprytextfield7">
<input name="phone" type="text" id="phone" maxlength="13" />
<span class="textfieldRequiredMsg">(i.e.: XXX-XXX-XXXX)</span><span class="textfieldInvalidFormatMsg">(i.e.: XXX-XXX-XXXX)</span></span><br/>
<br/>
<hr />
Additional information:<br />
<textarea name="comments" id="comments" cols="50" rows="5"></textarea>
<br/><br/>
<label for="file">Resume/CV (PDF or Word format only):</label>
<input type="hidden" name="max" value="100000"/>
<input type="file" name="file" id="file"/><br><br />
E-mail:
<span id="sprytextfield8">
<input type="text" name="email" id="email" />
<span class="textfieldRequiredMsg">Your e-mail address is required.</span><span class="textfieldInvalidFormatMsg">(i.e.: aaa@aaaa.com)</span></span><br/>
<br/>
<br/>
<input name="submit" type="submit" value="Send" />
<input type="reset" name="reset" value="Clear" />
</fieldset>
</form></p>
</div>
</div>
这是外部 PHP (upload.php) 文件,其括号类型与之前的 HTML 相同(相同的 CSS 和 HTML 正文):
<?php
$allowedExts = array("pdf", "doc");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "aaplication/doc"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$title=$_POST['title'];
$address=$_POST['address'];
$postal=$_POST['postal'];
$city=$_POST['city'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$province=$_POST['province'];
$date=gmdate("M d Y");
print"<p><b>$date</b></p>";
print"<p>Thank you $firstname $lastname! We will get back to you.</p>";
$to="someuser@gmail.com";
$subject="Candidate Resume";
$body="Date:$date \n Subject:$subject \n First Name:$firstname \n Last Name:$lastname \n Title:$title \n Address:$address \n City:$city \n Province:$province \n Postal Code:$postal \n Telephone:$phone \n Email:$email \n Additional Information:$comments \n\n";
mail($to,$subject,$body);
?>