dtotwai720621
dtotwai720621
2013-10-19 21:35
浏览 70

提交按钮在表单和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
    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.

    点赞 评论
  • duanpei8853
    duanpei8853 2013-11-13 00:39

    Check your PHP error log on your server to see if you can get some information on why its failing. That has helped me numerous times when debugging some code that wasn't working.

    点赞 评论

相关推荐