Jump to content

Recommended Posts

Hi guys need a little help with my form here is the code for the form

 

<form action="jobs.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
            <table width="483" border="0">
              <tr>
                <td width="66" align="right">Name:</td>
                <td width="407"><label>
                  <input name="Name" type="text" id="Name" accesskey="1" tabindex="1" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right">Email:</td>
                <td><label>
                  <input name="Email" type="text" id="Email" accesskey="2" tabindex="2" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right">Tel:</td>
                <td><label>
                  <input name="Tel" type="text" id="Tel" accesskey="3" tabindex="3" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right">CV:</td>
                <td><label>
                  <input name="JobCV" type="file" id="JobCV" accesskey="4" tabindex="4" size="30" />
                </label></td>
              </tr>
              <tr>
                <td align="right"> </td>
                <td><label>
                  <input name="Submit" type="submit" id="Submit" accesskey="5" tabindex="5" onclick="MM_validateForm('Name','','R','Email','','RisEmail','Tel','','RisNum');return document.MM_returnValue" value="send" />
                </label>
                  <label>
                    <input type="reset" name="Reset" id="Reset" value="Clear" accesskey="6" tabindex="6" />
                  </label></td>
              </tr>
            </table>
          </form>

 

 

I am using the following PHP code however the i keep getting directed to my error page and cant figure out why? any help would be gr8

 

<?php
// Receiving variables
@$Name = addslashes($_POST['Name']);
@$Email = addslashes($_POST['Email']);
@$Tel = addslashes($_POST['Tel']);
@$JobCV_Name = $_FILES['JobCV']['name'];
@$JobCV_Size = $_FILES['JobCV']['size'];
@$JobCV_Temp = $_FILES['JobCV']['tmp_name'];
@$JobCV_Mime_Type = $_FILES['JobCV']['type'];

function RecursiveMkdir($path)
{
   if (!file_exists($path)) 
   { 
      RecursiveMkdir(dirname($path));
      mkdir($path, 0777);
    }
  }


// Validation
if (strlen($Name) == 0 )
{
header("Location: Error.html");
exit;
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $Email))
{
header("Location: Error.html");
exit;
}

if ( $Tel <= 0)
{
header("Location: Error.html");
exit;
}

if( $JobCV_Size == 0)
{
header("Location: Error.html");
exit;
}
if( $JobCV_Size >30000000)
{
//delete file 
unlink($JobCV_Temp);
header("Location: Error.html");
exit;
}
if( $JobCV_Mime_Type != "application/msword" AND $JobCV_Mime_Type != "application/pdf" AND $JobCV_Mime_Type != "application/rtf" AND $JobCV_Mime_Type != "application/vnd.ms-artgalry" AND $JobCV_Mime_Type != "application/vnd.ms-asf" AND $JobCV_Mime_Type != "application/vnd.ms-excel" AND $JobCV_Mime_Type != "application/vnd.ms-lrm" AND $JobCV_Mime_Type != "application/vnd.ms-powerpoint" AND $JobCV_Mime_Type != "application/vnd.ms-project" AND $JobCV_Mime_Type != "application/vnd.ms-tnef" AND $JobCV_Mime_Type != "application/vnd.ms-works" AND $JobCV_Mime_Type != "application/vnd.mseq" AND $JobCV_Mime_Type != "application/vnd.msign" AND $JobCV_Mime_Type != "application/xml" AND $JobCV_Mime_Type != "application/xml-dtd" AND $JobCV_Mime_Type != "application/xml-external-parsed-entity" AND $JobCV_Mime_Type != "application/zip" )
{
unlink($JobCV_Temp);
header("Location: Error.html");
exit;
}
$uploadFile = "CV/".$JobCV_Name ;
if (!is_dir(dirname($uploadFile)))
  {
    @RecursiveMkdir(dirname($uploadFile)); 
  }
else
  {
  @chmod(dirname($uploadFile), 0777);
  }
@move_uploaded_file( $JobCV_Temp , $uploadFile); 
chmod($uploadFile, 0644);
$JobCV_URL = "http://http://www.advanceglassandglazing.co.uk/CV/".$JobCV_Name ;

//Sending Email to form owner
$pfw_header = "From: $Email\n"
  . "Reply-To: $Email\n";
$pfw_subject = "Job Opportunities";
$pfw_email_to = "[email protected]";
$pfw_message = "Name: $Name\n"
. "Email: $Email\n"
. "Tel: $Tel\n"
. "JobCV: $JobCV_URL\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n";
$pfw_subject = "Re: Job Opportunities";
$pfw_email_to = "$Email";
$pfw_message = "We have recieved your CV sucessfully one of our HR team will contact you!";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//saving record in a text file
$pfw_file_name = "Jobs.csv";
$pfw_first_raw = "Name,Email,Tel,JobCV\r\n";
$pfw_values = "$Name,$Email,$Tel,$JobCV_Name\r\n";
$pfw_is_first_row = false;
if(!file_exists($pfw_file_name))
{
$pfw_is_first_row = true ;
}
if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {
die("Cannot open file ($pfw_file_name)");
exit;
}
if ($pfw_is_first_row)
{
  if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {
  die("Cannot write to file ($pfw_filename)");
  exit;
  }
}
if (fwrite($pfw_handle, $pfw_values) === FALSE) {
  die("Cannot write to file ($pfw_filename)");
  exit;
}
fclose($pfw_handle);

header("Location: ThankYouJobs.html");

?>

 

Link to comment
https://forums.phpfreaks.com/topic/156764-form-upload/
Share on other sites

You should also use the print_r statement to show what the $_FILES array contains.

 

Your code also violates one of the prime rules of programming. It is not telling you which conditional statement is failing or way and simply redirects to one common error page for every possible error. Why are people redirect happy, just stay on one page and output everything you need.

 

Each error needs to output a unique error message telling which test failed and in most cases it should state why the test failed.

 

You should also perform all the tests and output all the errors at once, instead of finding one and stopping (redirecting.)

Link to comment
https://forums.phpfreaks.com/topic/156764-form-upload/#findComment-825605
Share on other sites

In your ereg function for email you have it set to if(! ereg(.....)) so meaning if the email does not match the regular expression then give the error page, try remove the !. Also its probably best to not use ereg as it will no longer be supported in future, use preg_match instead.

 

Check your regular expression. Other than that yeah output all variables and error that is given, as said above.

 

Also i dont know if it makes a difference with your file check where you use the word AND, why not use &&?

Link to comment
https://forums.phpfreaks.com/topic/156764-form-upload/#findComment-825890
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.