Jump to content

Help on Contact Form and File Upload


munky1018

Recommended Posts

Newb issue here. I'm trying to collect data from fields to send in an e-mail to myself and upload a file to a directory on our website. It worked once but our system crashed and I had to use a back-up. Now it does not upload and only e-mails me the "email" field and hidden "subject" field. Any help would be appreciated. I've spent way to much time trying to figure it out.

 

<?php

		if (isset($_REQUEST['desired_position']) && isset($_REQUEST['first_name']) && isset($_REQUEST['last_name']) && isset($_REQUEST['email']))
		//if "email" is filled out, send email
		  {
		  //send email
			$desired_position = $_REQUEST['desired_position'] ; 
			$first_name = $_REQUEST['first_name'] ;
			$last_name = $_REQUEST['last_name'] ;
			$address = $_REQUEST['address'] ;
			$address2 = $_REQUEST['address2'] ;
			$city = $_REQUEST['city'] ;
			$state = $_REQUEST['state'] ;
			$zipcode = $_REQUEST['zipcode'] ;
			$daytime_phone = $_REQUEST['daytime_phone'] ;
			$evening_phone = $_REQUEST['evening_phone'] ;
			$email = $_REQUEST['email'] ;
			$website = $_REQUEST['website'] ;
			$cover_letter = $_REQUEST['cover_letter'] ;
			$fromemail = '[email protected]' ;
			$resumelocation = 'http://www.domain.com/uploads/' ;
			$subject = $_REQUEST['subject'] ;
			if($desired_position == ""){
				$desired_position .= "n/a";
			}
			if($first_name == ""){
				$first_name .= "n/a";
			}
			if($last_name == ""){
				$last_name .= "n/a";
			}
			if($address == ""){
				$address .= "n/a";
			}
			if($address2 == ""){
				$address2 .= "n/a";
			}
			if($city == ""){
				$city .= "n/a";
			}
			if($state == ""){
				$state .= "n/a";
			}
			if($zipcode == ""){
				$zipcode .= "n/a";
			}
			if($daytime_phone == ""){
				$daytime_phone .= "n/a";
			}
			if($evening_phone == ""){
				$evening_phone .= "n/a";
			}
			if($email == ""){
				$email .= "n/a";
			}
			if($website == ""){
				$website .= "n/a";
			}
			if($cover_letter == ""){
				$cover_letter .= "n/a";
			}

			   // Configuration
			  $allowed_filetypes = array('.doc','.pdf','.text','.docx'); // These will be the types of file that will pass the validation.
			  $max_filesize = 1820000; // Maximum filesize in BYTES.
			  $upload_path = './uploadsxyz_traff/'; // The place the file will be uploaded to.

		   $filename = $_FILES['uploadfile']['name']; // Get the name of the file (including file extension).
		   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

		   // Check if the filetype is allowed, if not DIE and inform the user.
		   if(!in_array($ext,$allowed_filetypes))
			  die('The filetype you attempted to upload is not allowed. Please use .pdf, .doc, .docx or .txt only. Thank you.');

		   // Now check the filesize, if it is too large then DIE and inform the user.
		   if(filesize($_FILES['uploadfile']['tmp_name']) > $max_filesize)
			  die('The file you attempted to upload is too large.');

		   // Check if we can upload to the specified path, if not DIE and inform the user.
		   if(!is_writable($upload_path))
			  die('You cannot upload to the specified directory.');

		   // Upload the file to your specified path.
		   if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$upload_path . $filename))
				 echo 'Your application has been submitted successfully.'; // It worked.
			  else
				 echo 'There was an error during the file upload.  Please try again.'; // It failed .

			$message = "
			Desired Position : $desired_position \n
			Contact: $first_name \n
			Email: $last_name \n
			Address: $address \n
			Address 2: $address2 \n
			City: $city \n
			State: $state \n
			Zipcode: $zipcode \n
			Daytime Phone: $daytime_phone \n
			Evening Phone: $evening_phone \n
			E-mail: $email \n
			Website/Portfolio: $website \n
			Cover Letter/Comments: $cover_letter \n
			Resume Location: $resumelocation \n
			Subject: $subject";
		  	mail( "[email protected]", "$subject", $message, "From: $fromemail" );
		  	{
			header ('Location: http://www.domain.com/submitted.php');
			exit ();
			}
		   }
		  else
		//if "email" is not filled out, display the form
		  {
		  echo "Please complete entire form.";
		  }
		  
		?>
	<form id="form_211871" class="appnitro" enctype="multipart/form-data" method="post" action="<?= $_SERVER['PHP_SELF']; ?>">
	<ul>
	<li id="li_7" >
	<label class="description" for="element_7">Desired Position  </label>
	<div>
		<input id="element_7" name="desired_position" class="element text large" type="text" maxlength="255" value=""/> 
	</div>
        <p class="guidelines" id="guide_7"><small>Please state which position you are interested in.</small></p> 
	</li>		
        <li id="li_4" >
	<label class="description" for="element_4_1">Name </label>
	<span>
		<input id="element_4_1" name="first_name" class="element text" maxlength="255" size="28" value=""/>
		<label>First</label>
	</span>
	<span>
		<input id="element_4_2" name="last_name" class="element text" maxlength="255" size="28" value=""/>
		<label>Last</label>
	</span> 
	</li>		
        <li id="li_1" >
	<label class="description" for="element_1_1">Address </label>

	<div>
		<input id="element_1_1" name="address" class="element text large" value="" type="text"/>
		<label for="element_1_1">Street Address</label>
	</div>

	<div>
		<input id="element_1_2" name="address2" class="element text large" value="" type="text"/>
		<label for="element_1_2">Address Line 2</label>
	</div>

	<div class="left">
		<input id="element_1_3" name="city" class="element text medium" value="" type="text"/>
		<label for="element_1_3">City</label>
	</div>

	<div class="right">
		<input id="element_1_4" name="state" class="element text medium" value="" type="text"/>
		<label for="element_1_4">State</label>
	</div>

	<div class="left">
		<input id="element_1_5" name="zipcode" class="element text medium" maxlength="15" value="" type="text"/>
		<label for="element_1_5">Zip Code</label>
	</div>
	</li>
        		
        <li id="li_2" >
	<label class="description" for="element_2_1">Daytime Phone </label>
	<span>
		<input id="element_2_1" name="daytime_phone" class="element text" size="13" maxlength="13" value="" type="text"/>
		<label for="element_2_1">(###) ###-####</label>
	</span>
	</li>	
        	
        <li id="li_3" >
	<label class="description" for="element_3_1">Evening Phone </label>
	<span>
		<input id="element_3_1" name="evening_phone" class="element text" size="13" maxlength="13" value="" type="text"/>
		<label for="element_3_1">(###) ###-####</label>
	</span>		 
	</li>		
        
        <li id="li_5" >
	<label class="description" for="element_5">E-mail </label>
	<div>
		<input id="element_5" name="email" class="element text medium" type="text" maxlength="255" value=""/> 
	</div> 
	</li>		
        
        <li id="li_6" >
	<label class="description" for="element_6">Web Site / Portfolio </label>
	<div>
		<input id="element_6" name="website" class="element text medium" type="text" maxlength="255" value="http://"/> 
	</div> 
	</li>		
        
        <li id="li_9" >
	<label class="description" for="element_9">Upload a Resume </label>
	<div>
		<input id="element_9" name="uploadfile" class="element file" type="file"/> 
	</div> <p class="guidelines" id="guide_9"><small>File types accepted. .DOC, .PDF, .TXT</small></p> 
	</li>		
        
        <li id="li_8" >
	<label class="description" for="element_8">Cover Letter / Comments </label>
	<div>
		<textarea id="element_8" name="cover_letter" class="element textarea large"></textarea> 
	</div> 
	</li>

	<li class="buttons">
		    <input type="hidden" name="required" value="email,phone"/> <!-- Required Fields -->
                <input type="hidden" name="subject" value="Job Posting"/>
			<input type="image" src="../images/bluearrow.png" title="Submit Resume" width="20" height="19" class="formbutton" value="Submit Resume"/>Submit Resume
	</li>
	</ul>
	</form>	
        <?php ?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/204283-help-on-contact-form-and-file-upload/
Share on other sites

While debugging, remove the redirect.  Since you're using the POST method, change all the $_REQUEST to $_POST and put

<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
?>

at the start of the script. This will dump what's being submitted to the script.

 

Ken

This is what I have now but I still get the same result.

<?php
		echo '<pre>' . print_r($_POST,true) . '</pre>';

		if (isset($_POST['desired_position']) && isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email']))
		//if "email" is filled out, send email
		  {
		  //send email
			$desired_position = $_POST['desired_position'] ; 
			$first_name = $_POST['first_name'] ;
			$last_name = $_POST['last_name'] ;
			$address = $_POST['address'] ;
			$address2 = $_POST['address2'] ;
			$city = $_POST['city'] ;
			$state = $_POST['state'] ;
			$zipcode = $_POST['zipcode'] ;
			$daytime_phone = $_POST['daytime_phone'] ;
			$evening_phone = $_POST['evening_phone'] ;
			$email = $_POST['email'] ;
			$website = $_POST['website'] ;
			$cover_letter = $_POST['cover_letter'] ;
			$fromemail = '[email protected]' ;
			$resumelocation = 'http://www.trafficbuildersusa.com/test/careers/uploadsxyz_traff/' ;
			$subject = $_POST['subject'] ;
			if($desired_position == ""){
				$desired_position .= "n/a";
			}
			if($first_name == ""){
				$first_name .= "n/a";
			}
			if($last_name == ""){
				$last_name .= "n/a";
			}
			if($address == ""){
				$address .= "n/a";
			}
			if($address2 == ""){
				$address2 .= "n/a";
			}
			if($city == ""){
				$city .= "n/a";
			}
			if($state == ""){
				$state .= "n/a";
			}
			if($zipcode == ""){
				$zipcode .= "n/a";
			}
			if($daytime_phone == ""){
				$daytime_phone .= "n/a";
			}
			if($evening_phone == ""){
				$evening_phone .= "n/a";
			}
			if($email == ""){
				$email .= "n/a";
			}
			if($website == ""){
				$website .= "n/a";
			}
			if($cover_letter == ""){
				$cover_letter .= "n/a";
			}

			   // Configuration
			  $allowed_filetypes = array('.doc','.pdf','.text','.docx'); // These will be the types of file that will pass the validation.
			  $max_filesize = 1820000; // Maximum filesize in BYTES.
			  $upload_path = './uploadsxyz_traff/'; // The place the file will be uploaded to.

		   $filename = $_FILES['uploadfile']['name']; // Get the name of the file (including file extension).
		   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

		   // Check if the filetype is allowed, if not DIE and inform the user.
		   if(!in_array($ext,$allowed_filetypes))
			  die('The filetype you attempted to upload is not allowed. Please use .pdf, .doc, .docx or .txt only. Thank you.');

		   // Now check the filesize, if it is too large then DIE and inform the user.
		   if(filesize($_FILES['uploadfile']['tmp_name']) > $max_filesize)
			  die('The file you attempted to upload is too large.');

		   // Check if we can upload to the specified path, if not DIE and inform the user.
		   if(!is_writable($upload_path))
			  die('You cannot upload to the specified directory.');

		   // Upload the file to your specified path.
		   if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$upload_path . $filename))
				 echo 'Your application has been submitted successfully.'; // It worked.
			  else
				 echo 'There was an error during the file upload.  Please try again.'; // It failed .

			$message = "
			Desired Position : $desired_position \n
			Contact: $first_name \n
			Email: $last_name \n
			Address: $address \n
			Address 2: $address2 \n
			City: $city \n
			State: $state \n
			Zipcode: $zipcode \n
			Daytime Phone: $daytime_phone \n
			Evening Phone: $evening_phone \n
			E-mail: $email \n
			Website/Portfolio: $website \n
			Cover Letter/Comments: $cover_letter \n
			Resume Location: $resumelocation \n
			Subject: $subject";
		  	mail( "[email protected]", "$subject", $message, "From: $fromemail" );
		  	{
			header ('Location: http://www.trafficbuildersusa.com/');
			exit ();
			}
		   }
		  else
		//if "email" is not filled out, display the form
		  {
		  echo "Please complete entire form.";
		  }
		  
		?>

 

Not the email contents.

 

The line

<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
?>

Should print what's being submitted. That's what you need to show us. But you have to comment out or remove

<?php
header ('Location: http://www.trafficbuildersusa.com/');
?>

to see it.

 

Ken

I removed that line completely and it doesn't not print. It acts like always.

 <?php
		echo '<pre>' . print_r($_POST,true) . '</pre>';

		if (isset($_POST['desired_position']) && isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email']))
		//if "email" is filled out, send email
		  {
		  //send email
			$desired_position = $_POST['desired_position'] ; 
			$first_name = $_POST['first_name'] ;
			$last_name = $_POST['last_name'] ;
			$address = $_POST['address'] ;
			$address2 = $_POST['address2'] ;
			$city = $_POST['city'] ;
			$state = $_POST['state'] ;
			$zipcode = $_POST['zipcode'] ;
			$daytime_phone = $_POST['daytime_phone'] ;
			$evening_phone = $_POST['evening_phone'] ;
			$email = $_POST['email'] ;
			$website = $_POST['website'] ;
			$cover_letter = $_POST['cover_letter'] ;
			$fromemail = '[email protected]' ;
			$resumelocation = 'http://www.trafficbuildersusa.com/test/careers/uploadsxyz_traff/' ;
			$subject = $_POST['subject'] ;
			if($desired_position == ""){
				$desired_position .= "n/a";
			}
			if($first_name == ""){
				$first_name .= "n/a";
			}
			if($last_name == ""){
				$last_name .= "n/a";
			}
			if($address == ""){
				$address .= "n/a";
			}
			if($address2 == ""){
				$address2 .= "n/a";
			}
			if($city == ""){
				$city .= "n/a";
			}
			if($state == ""){
				$state .= "n/a";
			}
			if($zipcode == ""){
				$zipcode .= "n/a";
			}
			if($daytime_phone == ""){
				$daytime_phone .= "n/a";
			}
			if($evening_phone == ""){
				$evening_phone .= "n/a";
			}
			if($email == ""){
				$email .= "n/a";
			}
			if($website == ""){
				$website .= "n/a";
			}
			if($cover_letter == ""){
				$cover_letter .= "n/a";
			}

			   // Configuration
			  $allowed_filetypes = array('.doc','.pdf','.text','.docx'); // These will be the types of file that will pass the validation.
			  $max_filesize = 1820000; // Maximum filesize in BYTES.
			  $upload_path = './uploadsxyz_traff/'; // The place the file will be uploaded to.

		   $filename = $_FILES['uploadfile']['name']; // Get the name of the file (including file extension).
		   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

		   // Check if the filetype is allowed, if not DIE and inform the user.
		   if(!in_array($ext,$allowed_filetypes))
			  die('The filetype you attempted to upload is not allowed. Please use .pdf, .doc, .docx or .txt only. Thank you.');

		   // Now check the filesize, if it is too large then DIE and inform the user.
		   if(filesize($_FILES['uploadfile']['tmp_name']) > $max_filesize)
			  die('The file you attempted to upload is too large.');

		   // Check if we can upload to the specified path, if not DIE and inform the user.
		   if(!is_writable($upload_path))
			  die('You cannot upload to the specified directory.');

		   // Upload the file to your specified path.
		   if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$upload_path . $filename))
				 echo 'Your application has been submitted successfully.'; // It worked.
			  else
				 echo 'There was an error during the file upload.  Please try again.'; // It failed .

			$message = "
			Desired Position : $desired_position \n
			Contact: $first_name \n
			Email: $last_name \n
			Address: $address \n
			Address 2: $address2 \n
			City: $city \n
			State: $state \n
			Zipcode: $zipcode \n
			Daytime Phone: $daytime_phone \n
			Evening Phone: $evening_phone \n
			E-mail: $email \n
			Website/Portfolio: $website \n
			Cover Letter/Comments: $cover_letter \n
			Resume Location: $resumelocation \n
			Subject: $subject";
		  	mail( "[email protected]", "$subject", $message, "From: $fromemail" );
		  	
		  }
		  

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.