dtotwai720621 2013-10-19 21:35
浏览 72
已采纳

提交按钮在表单和PHP中不起作用

I have a problem with the submit button: it just won't work. It seems to work fine with my previous forms. I'm using the Spry Validation as well. It's a simple HTML with a PHP. I can't see where is my mistake (and I'm just starting to learn PHP). I've looked around the forum already and on the internet, but I couldn't find an answer for my problem. I'm trying to get a basic form e-mailed to me with an option to upload a file within the same form. Does the problem come from the form formatting or the PHP file? Here are the codes I have: This is the HTML form located within a <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>

This is the external PHP (upload.php) file located with the same bracket type of bracket as the previous HTML(same CSS and HTML body):

<?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 
 Subject:$subject 
 First Name:$firstname 
 Last Name:$lastname 
 Title:$title 
 Address:$address 
 City:$city 
 Province:$province 
 Postal Code:$postal 
 Telephone:$phone 
 Email:$email 
 Additional Information:$comments 

";

mail($to,$subject,$body);

?>
  • 写回答

2条回答 默认 最新

  • dongping1012 2013-11-13 01:13
    关注

    Your script works, just increase the filesize value in the if statement to something the will accommodate these types of files. ($_FILES["file"]["size"] < 500000)

    Your were only allowing for 19k.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大