Only allow form submit of pdf/images not ever blank : <p>Hi I have a website which the page logic should only accept submit under two conditions:</p>

<p>1) if the captcha is actively checked</p>

<p>and </p>

<p>2) if at least one file is attached (only pdf and image file types are allowed up to three total) are attached. </p>

<p>the issue is that we are receiving blank applications however, I am seeing a scenario where you can attach non pdfs/images with a pdf/image and still submit which strips all attachments.</p>

<p>proper behavior should be:
prevent submit if non pdf/image type attached show error message "Only image or pdf can be uploaded" and then a message stating this and preventing form submit at the bottom of the page in red just like the other errors.</p>

<p>Be polite. Thanks. :-)</p>

<p>Page URL: <a href="http://www.barona.com/about-barona/community-relations/community-giving-guidelines/" rel="nofollow">http://www.barona.com/about-barona/community-relations/community-giving-guidelines/</a></p>

<p>PHP (to test replace youremail with your email address, thanks!):</p>

<pre><code>&lt;?php
ini_set('display_errors', 'off');
$to                 = 'youremail@gmail.com';
$from               = 'youremail@gmail.com';
$subject            = 'New Application';
$allowed_extensions = array(
    '.pdf',
    '.jpeg',
    '.jpg',
    '.png',
    '.gif',
    '.bmp'
);
$file1              = '';
$file2              = '';
$file3              = '';
$filename1          = '';
$filename2          = '';
$filename3          = '';
//echo  "1"; 
if (!empty($_FILES['file1']['name'])) {
    //echo  "File 1 exists"; 
    $filename1 = $_FILES['file1']['name'];
    $extension = '.' . strtolower(array_pop(explode('.', $filename1)));
    $size1     = $_FILES['file1']['size'];
    $mime1     = $_FILES['file1']['type'];
    $tmp1      = $_FILES['file1']['tmp_name'];
    if (in_array($extension, $allowed_extensions)) {
        $file1 = fopen($tmp1, 'rb');
        $data1 = fread($file1, filesize($tmp1));
        // Now read the file content into a variable
        fclose($file1);
        // close the file
        $data1 = chunk_split(base64_encode($data1));
        // Now we need to encode it and split it into acceptable length lines
        $file1 = $filename1;
    } else {
        $filename1 = '';
    }
}
//file 2:
if (!empty($_FILES['file2']['name'])) {
    //echo  "File 2 exists"; 
    $filename2 = $_FILES['file2']['name'];
    $extension = '.' . strtolower(array_pop(explode('.', $filename2)));
    $tmp2      = $_FILES['file2']['tmp_name'];
    $size2     = $_FILES['file2']['size'];
    $mime2     = $_FILES['file2']['type'];
    if (in_array($extension, $allowed_extensions)) {
        $file2 = fopen($tmp2, 'rb');
        $data2 = fread($file2, filesize($tmp2));
        // Now read the file content into a variable
        fclose($file2);
        // close the file
        $data2 = chunk_split(base64_encode($data2));
        // Now we need to encode it and split it into acceptable length lines
        $file2 = $filename2;
    } else {
        $filename2 = '';
    }
}
//File 3:
if (!empty($_FILES['file3']['name'])) {
    //echo  "File 3 exists"; 
    $filename3 = $_FILES['file3']['name'];
    $extension = '.' . strtolower(array_pop(explode('.', $filename3)));
    $tmp3      = $_FILES['file3']['tmp_name'];
    $size3     = $_FILES['file3']['size'];
    $mime3     = $_FILES['file3']['type'];
    if (in_array($extension, $allowed_extensions)) {
        $file3 = fopen($tmp3, 'rb');
        $data3 = fread($file3, filesize($tmp3));
        // Now read the file content into a variable
        fclose($file3);
        // close the file
        $data3 = chunk_split(base64_encode($data3));
        // Now we need to encode it and split it into acceptable length lines
        $file3 = $filename3;
    } else {
        $filename3 = '';
    }
}
//echo  "2"; 
//Only allow image or pdf.
$message = "&lt;table border='1' style='width:80%'&gt;&lt;tr&gt;&lt;td&gt;File 1: &lt;/td&gt;&lt;td&gt;$filename1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;File 2: &lt;/td&gt;&lt;td&gt;$filename2&lt;td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;File 3: &lt;/td&gt;&lt;td&gt;$filename3&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
// email fields: to, from, subject, and so on
$headers = "From: $from\n";
$headers .= "Reply-To: $to\n";
$headers .= "BCC: cpeterson@barona.com";
// boundary 
$semi_rand     = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment 
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed, html;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary 
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=ISO-8859-1\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
if (!empty($file1)) {
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name='$filename1'\n" . "Content-Disposition: attachment;\n" . " filename=$filename1\n" . "Content-Transfer-Encoding: base64\n\n" . $data1 . "\n\n";
    $message .= "--{$mime_boundary}\n";
}
if (!empty($file2)) {
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name='$filename2'\n" . "Content-Disposition: attachment;\n" . " filename=$filename2\n" . "Content-Transfer-Encoding: base64\n\n" . $data2 . "\n\n";
    $message .= "--{$mime_boundary}\n";
}
if (!empty($file3)) {
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name='$filename3'\n" . "Content-Disposition: attachment;\n" . " filename=$filename3\n" . "Content-Transfer-Encoding: base64\n\n" . $data3 . "\n\n";
    $message .= "--{$mime_boundary}\n";
}
// send
$ok = @mail($to, $subject, $message, $headers, '-fnoreply@yourmailer.com');
if ($ok) {
    //echo "&lt;p&gt;Thank you for submitting your application to: $to!&lt;/p&gt;";
header("Location: ../../../about-barona/community-relations/community-giving-guidelines/thanks/"); /* Redirect browser */
exit();
} else {
    //echo "&lt;p&gt;mail could not be sent!&lt;/p&gt;";
header("Location: ../../../club-barona/email-signup/error/"); /* Redirect browser */
exit();
}
?&gt;
</code></pre>

<p>Wordpress HTML:</p>

<pre><code>&lt;h2&gt;COMMUNITY GIVING GUIDELINES &amp; DONATION APPLICATION&lt;/h2&gt;&lt;p&gt;In an effort to better serve you, Barona will only review requests via an online donation application. To be considered for a donation or sponsorship, you must complete the online application. Requests submitted via email, mail, phone, or fax will not be accepted. All requests will be screened and reviewed for consideration by the Community Relations Committee. In making determinations on contribution requests, the Committee places emphasis on well-managed non-profit organizations and programs. Funding decisions are also based on the quality of the organizations programs and their support of Barona Resort &amp; Casino’s key areas of focus. Additional consideration includes the scope of each program and the overall impact on the community. Barona maintains the flexibility to accommodate new and innovative approaches to meeting the needs of the community.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Due to the volume of requests received, donation requests for auction and raffle items must be submitted at least 60 – 90 days prior to the date the donation is needed.&lt;/li&gt;&lt;li&gt;Sponsorship requests should be submitted by October for consideration in the following year, as planning is based on a calendar year.&lt;/li&gt;&lt;li&gt;Sponsorships exceeding $10,000 must include performance measurement criteria and the requestor must be prepared to submit a report of achievement.&lt;/li&gt;&lt;li&gt;We will respond to all requests with the decision of the committee, regardless of the outcome within 6 - 8 weeks of review.&lt;/li&gt;&lt;/ul&gt;
&lt;h3&gt;We generally &lt;b&gt; exclude &lt;/b&gt; requests that benefit:&lt;/h3&gt;
&lt;ul&gt; 
    &lt;li&gt;Local sports organizations &lt;/li&gt;

    &lt;li&gt;An individual person or family &lt;/li&gt;

    &lt;li&gt;General operating expenses &lt;/li&gt;

    &lt;li&gt;Political candidates or organizations &lt;/li&gt;

    &lt;li&gt;Film or documentary productions &lt;/li&gt;

    &lt;li&gt;Memorials, endowments, or grants &lt;/li&gt;

    &lt;li&gt;Organizations outside of California &lt;/li&gt;

    &lt;li&gt;Travel expenses &lt;/li&gt;

    &lt;li&gt;Groups seeking educational or travel grants for contests, pageants, trips or conventions &lt;/li&gt;

    &lt;li&gt;Loan or loan guarantees &lt;/li&gt;

    &lt;li&gt;Capital improvement or building funds &lt;/li&gt;
  &lt;/ul&gt;
&lt;p&gt;&lt;input id="chkTerms" name="chkTerms" onclick="validate();" required="required" type="checkbox" value="0"&gt; I have read and understand the Community Giving Guidelines. Thank you for contacting Barona Resort &amp;amp; Casino regarding a contribution towards your organization. Please note that this online application must be completed in its entirety and, if necessary, submitted with all appropriate supporting documents.&lt;/p&gt;&lt;form action="../../../wp-content/themes/barona/form-to-email.php" enctype="multipart/form-data" method="post"&gt; 
&lt;div id="DonationApplicationFormContent" style="width: 700px; margin: 10px -150px !important; display: none;"&gt;
&lt;hr /&gt;
&lt;h2&gt;Instructions &lt;/h2&gt;
&lt;p&gt;Follow the directions below to submit your &lt;strong&gt;&lt;a href="/wp-content/uploads/2015/10/DonationApplicationForm.pdf" target="_blank"&gt;Donation Application Form&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;iframe width="560" height="315" src="https://www.youtube.com/embed/G-SDuvlur8o" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;

&lt;h3 style="margin: 0;"&gt;Step 1&lt;/h3&gt;
&lt;p&gt;Download the Donation Application Form PDF.&lt;br /&gt;&lt;small&gt;Note: Safari users, right click the "Download Now" button and select "Download Linked File As".&lt;/small&gt;&lt;br /&gt;&lt;br /&gt;[easy_media_download url="/wp-content/uploads/2015/10/DonationApplicationForm.pdf" force_dl="1"]&lt;/p&gt;
&lt;h3 style="margin: 0;"&gt;Step 2&lt;/h3&gt;
&lt;strong&gt;Print&lt;/strong&gt; or &lt;strong&gt;complete&lt;/strong&gt; the form using &lt;strong&gt;&lt;a href="https://get.adobe.com/reader" target="_blank"&gt;Adobe Acrobat Reader&lt;/a&gt;&lt;/strong&gt;. You can download Adobe Acrobat for free at &lt;a href="https://get.adobe.com/reader" target="_blank"&gt;https://get.adobe.com/reader&lt;/a&gt;
&lt;/p&gt;
&lt;h3 style="margin: 0;"&gt;Step 3&lt;/h3&gt;
Click &lt;strong&gt;Browse&lt;/strong&gt; to upload the completed &lt;strong&gt;Donation Application Form&lt;/strong&gt; along with any supporting documents (images or PDF).
&lt;/p&gt;
&lt;h3 style="margin: 0;"&gt;Step 4&lt;/h3&gt;
&lt;p&gt;Click the &lt;strong&gt;Submit&lt;/strong&gt; button below to complete your submission. &lt;br /&gt;
&lt;br /&gt;
OR 
&lt;br /&gt;&lt;br /&gt;
Email your completed PDF document with any supporting documents to &lt;a href="mailto: donationapplicationsbarona@gmail.com"&gt;donationapplicationsbarona@gmail.com&lt;/a&gt;.
&lt;/p&gt;
Upload event brochures, marketing materials or other documents. Upload images or PDF files only. (Limit: 5MB max per file):
&lt;table&gt;
&lt;tr style="height: 30px;"&gt;
&lt;td&gt;File 1:&lt;input type="file" id="file1" name="file1"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height: 30px;"&gt;
&lt;td&gt;File 2:&lt;input type="file" id="file2"  name="file2"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height: 30px;"&gt;
&lt;td&gt;File 3: &lt;input type="file" id="file3"  name="file3"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;tr &gt;
&lt;td&gt;
&lt;div class="g-recaptcha" id="rcaptcha" data-sitekey="6Let2wwTAAAAAJaUZQGTCRy6Pv4YYLoQjsLUH6hs"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div id="captcha" aria-live="assertive"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height: 80px;"&gt;
&lt;td&gt;&lt;input tabindex="11" title="Submit" type="submit" value="Submit" onclick="return get_action(this);"&gt;&lt;input tabindex="12" title="Reset" type="reset" value="Reset"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;label id="lblStatus"&gt;*Required.&lt;/label&gt;&lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p>Page source:</p>

<p>see page. :-)</p>

<p>Please help fix it so no blank applications can be received. as well as only pdf/images allowed before submit. willing to install a js file. please be as thorough and I will select you as top vote/winner. be good my coder friends! Long live privacy!</p>
