Hello all. I have been working very diligently trying to figure this out for myself but I have reached a point of stand-still. Basically, I have this (semi-weird) contact form that I’ve used for years adapted from an old learn-to-code book. Now I have this uploader (php/js) that I’m adding to it. Separately they work fine (at least to me) but I’m having issue trying to combine these 2 elements…
Specifically, I would really like the uploader to communicate back to the contact form the names of the uploaded files (quantity of upload can vary considerably) so that those names can be included in the generated email. Can someone please help in this endeavor!!!?
CONTACT FORM W/ UPLOADER
[CODE]<?php
if (array_key_exists(‘send’, $_POST)) {
// mail processing script
$to = ’[email protected]’;
$me = ’[email protected]’;
$subject = ‘Score Call’;
// list expected fields
$expected = array(‘name’, ‘age’, ‘gender’, ‘mailing’, ‘city’, ‘state’, ‘zipcode’, ‘phone’, ’email’, ‘title’, ‘duration’, ‘instrumentation’, ‘agreement’, ‘upl’);
// set required fields
$required = array(‘name’, ‘age’, ‘gender’, ‘mailing’, ‘city’, ‘state’, ‘zipcode’, ‘phone’, ’email’, ‘title’, ‘duration’, ‘instrumentation’, ‘agreement’);
// set additional headers
$headers = ‘From: <[email protected]>’;
// set the include
$process = ‘includes/application.inc.php’;
if (file_exists($process) && is_readable($process)) {
include($process);
}
else {
$mailSent = false;
mail($me, ‘Server Problem’, “$process cannot be read”, $headers);
}
}
?>
<!DOCTYPE html>
<html lang=”en-US”>
<head>
<meta charset=”UTF-8″>
<link href=”css/style.css” rel=”stylesheet”>
</head>
<body>
<div id=”appContainer”>
<?php
if ($_POST && isset($missing) && !empty($missing)) {
?>
<p class=”warning”>Please complete the missing item(s) indicated.</p>
<?php
}
elseif ($_POST && !$mailSent) {
?>
<p class=”warning”>Sorry, there was a problem sending your message. Please try again later.</p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p class=”success”>Your application has been submitted. A member of Calliope’s Call will be in touch! Thank you!</p>
<?php } ?>
<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post” name=”application” id=”application” onSubmit=”MM_validateForm(‘name’,”,’R’,’email’,”,’RisEmail’);return document.MM_returnValue”>
<table class=”applicationForm formText”>
<tr>
<td class=”formTextColOne”><label for=”name”>Full Name: <?php
if (isset($missing) && in_array(‘name’, $missing)) { ?>
<span class=”warning”>Please enter your Full Name</span><?php } ?>
</label>
<input name=”name” type=”text” class=”textInput” id=”name”
<?php if (isset($missing)) {
echo ‘value=”‘.htmlentities($_POST[‘name’], ENT_QUOTES).'”‘;
} ?>
></td>
<td class=”formTextColTwo”><label for=”age”>Age: <?php
if (isset($missing) && in_array(‘age’, $missing)) { ?>
<span class=”warning”>Please enter your Age</span><?php } ?>
</label>
<input name=”age” type=”text” class=”textInput” id=”age”
<?php if (isset($missing)) {
echo ‘value=”‘.htmlentities($_POST[‘age’], ENT_QUOTES).'”‘;
} ?>
></td>
<td class=”formTextColThree”><span class=”formText”>Gender:</span><br>
<select name=”gender” size=”1″>
<option value=”” selected>Please Select:</option>
<option value=”Male”>Male</option>
<option value=”Female”>Female</option>
</select><?php
if (isset($missing) && in_array(‘gender’, $missing)) { ?>
<span class=”warning”>Please Select Your Gender</span><?php } ?>
</td>
</tr>
<tr>
<td class=”formTextColOne”> </td>
<td class=”formTextColTwo”><input type=”submit” name=”send” id=”send” value=”Submit Application”></td>
<td class=”formTextColThree”> </td>
</tr>
</table>
</form>
<form id=”upload” method=”post” action=”upload.php” enctype=”multipart/form-data”>
<div id=”drop”>
<span style=”font-size:2em;”>Upload</span> your biography (please limit to 1 paragraph or 300 words), recording, and any applicable supporting documentation.
<a>Browse</a>
<input type=”file” name=”upl” multiple />
</div>
<ul>
<!– The file uploads will be shown here –>
</ul>
</form>
</div>
<!– JavaScript Includes –>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”></script>
<script src=”js/jquery.knob.js”></script>
<!– jQuery File Upload Dependencies –>
<script src=”js/jquery.ui.widget.js”></script>
<script src=”js/jquery.iframe-transport.js”></script>
<script src=”js/jquery.fileupload.js”></script>
<!– Our main JS file –>
<script src=”js/script.js”></script>
</body>
</html>
And then the application processor
[code=php]<?php
// create empty array for any missing fields
$missing = array();
// assume that there is nothing suspect
$suspect = false;
// create a pattern to locate suspect phrases
$pattern = ‘/Content-Type:|Bcc:|CC:/i’;
// function to check for suspect phrases
function isSuspect($val, $pattern, &$suspect) {
// if the variable is an array, loop through each element
// and pass it recursively back to the same function
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}
else {
// if one of the suspect phrases is found, set Boolean to true
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
}
// check the $_POST array and any subarrays for suspect content
isSuspect($_POST, $pattern, $suspect);
if ($suspect ) {
$mailSent = false;
unset($missing);
}
else {
// process the $_POST variables
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key, $required)) {
array_push($missing, $key);
}
// otherwise, assign to a variable of the same name as $key
elseif (in_array($key, $expected)) {
${$key} = $temp;
}
}
}
// validate the email address
if (!empty($email)) {
// regex to identify illegal characters in email address
$checkEmail = ‘/^[^@]+@[^srn'”;,@%]+$/’;
// reject the email address if it doesn’t match
if (!preg_match($checkEmail, $email)) {
$suspect = true;
$mailSent = false;
unset($missing);
}
}
// validate the comments
// regex to identify illegal characters in email address
//$link = false;
//$checkComments = ‘/(http://|www)/’;
//if(preg_match($checkComments, stripcslashes($comments))){
// $link = true;
// $mailSent = false;
// unset($missing);
//}
//else{
// go ahead only if not suspect and all required fields OK
if (!$suspect && empty($missing)) {
// initialize the $message variable
$message = ”;
// loop through the $expected array
foreach($expected as $item) {
// assign the value of the current item to $val
if (isset(${$item})) {
$val = ${$item};
}
// if it has no value, assign ‘Not Selected’
else {
$val = ‘Not selected’;
}
// if an array, expand as comma-separated string
if (is_array($val)) {
$val = implode(‘, ‘, $val);
}
// add label and value to the message body
$message .= ucfirst($item).”: $valnn”;
}
// add FILES to message
//$newVal = implode (‘, ‘, $_FILES[‘upl’][‘name’]);
//$message .= ucfirst($_FILES[‘upl’][‘name’]).”: $newValnn”;
// limit line length
$message = wordwrap($message, 70);
// create Reply-To header
if (!empty($email)) {
$headers .= “rnReply-To: $email”;
}
// send it
$mailSent = mail($to, $subject, $message, $headers);
if ($mailSent) {
// $missing is no longer needed if the email is sent, so unset it
unset($missing);
}
}
// }
?>
And the, for now, separate uploading processor:
[code=php]<?php
(move_uploaded_file($_FILES[‘upl’][‘tmp_name’], ‘../public_ftp/incoming/’.$_FILES[‘upl’][‘name’].time()))
?>
I know I’m missing something stupid here but I’m stuck… Any help would be greatly appreciated!