title: PHP form with checkboxes, radio buttons and file attachment
body: <p>I'm having a nightmare with this PHP form where a user can fill it in, attach a doc/pdf and submit. After trying to sort it out with previous code I've used, I've stripped it out and think I should just start again in the hope you geniuses can help!</p>
  
  <p>Here is the HTML of contact.php:</p>
  
  <pre><code>&lt;form action="" method="post" name="contact" id="contact"&gt;
  
  &lt;p&gt;Job Title:*&lt;br /&gt;
  &lt;input name="position" type="text" /&gt;&lt;/p&gt;
  
  &lt;p&gt;Nationality:*&lt;br /&gt;
  &lt;select name="nationality"&gt;
    &lt;option value=""&gt;-- select one --&lt;/option&gt;
    &lt;option value="Afghan"&gt;Afghan&lt;/option&gt;
    &lt;option value="Albanian"&gt;Albanian&lt;/option&gt;
    &lt;option value="Algerian"&gt;Algerian&lt;/option&gt;
    &lt;option value="Zambian"&gt;Zambian&lt;/option&gt;
    &lt;option value="Zimbabwean"&gt;Zimbabwean&lt;/option&gt;
  &lt;/select&gt;
  &lt;/p&gt;
  
  &lt;p&gt;Which country are you currently living in?*&lt;br /&gt;
  &lt;select name="country"&gt;
  &lt;option value=""&gt;-- select one --&lt;/option&gt;
  &lt;option value="United Kingdom"&gt;United Kingdom&lt;/option&gt;
  &lt;option value="Afghanistan"&gt;Afghanistan&lt;/option&gt;
  &lt;option value="Africa"&gt;Africa&lt;/option&gt;
  &lt;option value="Zambia"&gt;Zambia&lt;/option&gt;
  &lt;option value="Zimbabwe"&gt;Zimbabwe&lt;/option&gt;
  &lt;/select&gt;
  &lt;/p&gt;
  
  &lt;label class="radio" for="checkRight"&gt;Yes/No question?&lt;/label&gt;&lt;br /&gt;
  &lt;input class="radio" type="radio" name="right" value="Yes" /&gt; Yes
  &lt;input class="radio" type="radio" name="right" value="No" /&gt; No
  &lt;input class="radio" type="radio" name="right" value="N/A" /&gt; Not applicable
  
  &lt;p&gt;Yes/No question?&lt;br /&gt;
  &lt;select name="continue"&gt;
  &lt;option value=""&gt;-- select one --&lt;/option&gt;
  &lt;option value="Yes"&gt;Yes&lt;/option&gt;
  &lt;option value="No"&gt;No&lt;/option&gt;
  &lt;/select&gt;
  &lt;/p&gt;
  
  &lt;p&gt;Select your resorts:&lt;br /&gt;
  Resort 1&lt;input name="res1" type="checkbox" value="Resort 1" /&gt;
  Resort 2&lt;input name="res2" type="checkbox" value="Resort 2" /&gt;
  Resort 3&lt;input name="res3" type="checkbox" value="Resort 3" /&gt;
  Resort 4&lt;input name="res4" type="checkbox" value="Resort 4" /&gt;
  Resort 5&lt;input name="res5" type="checkbox" value="Resort 5" /&gt;
  Resort 6&lt;input name="res6" type="checkbox" value="Resort 6" /&gt;    
  &lt;/p&gt;
  
  &lt;p&gt;Don't send form unless this is checked:* &lt;input type="checkbox" name="parttime" value="Yes" /&gt;&lt;/p&gt;
  
  &lt;p&gt;Date of arrival: &lt;input name="arrive" id="datepick" /&gt;&lt;br /&gt;
  Date of departure: &lt;input name="depart" id="datepick2" /&gt;&lt;/p&gt;
  
  &lt;script type="text/javascript" src="assets/scripts/datepickr/datepickr.js"&gt;&lt;/script&gt;
  &lt;link href="assets/scripts/datepickr/datepickr.css" rel="stylesheet"&gt;
  
  &lt;script type="text/javascript"&gt;
  new datepickr('datepick');
  new datepickr('datepick2', {
  });
  &lt;/script&gt;
  
  
  &lt;p&gt;Name:*&lt;br /&gt;
  &lt;input name="name" type="text" /&gt;&lt;/p&gt;
  
  &lt;p&gt;E-mail:*&lt;br /&gt;
  &lt;input name="email" type="text" /&gt;&lt;/p&gt;
  
  &lt;p&gt;Telephone:*&lt;br /&gt;
  &lt;input name="telephone" type="text" class="ctextField" /&gt;&lt;/p&gt;
  
  &lt;p&gt;Upload CV (Word of PDF formats only):&lt;br /&gt;
  &lt;input type="file" name="cv" class="textfield"&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;input name="submit" value="Submit Enquiry" class="submitButton" type="submit" /&gt;&lt;div style="visibility:hidden; width:1px; height:1px"&gt;&lt;input name="url" type="text" size="45" id="url" /&gt;&lt;/div&gt;&lt;/p&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>By the way, the date boxes work so excuse the Javascript in there!</p>
  
  <p>To prevent SPAM I've used a trick where there's a hidden URL field which must be left blank for the form to submit which you can see in the PHP.</p>
  
  <p>Below is where I'm at with the PHP which is placed above the header of contact.php...</p>
  
  <pre><code>&lt;?php
  
  if (array_key_exists('submit', $_POST)) {
  $position = $_POST['position'];
  $arrive = $_POST['arrive'];
  $nationality = $_POST['nationality'];
  $parttime = $_POST['parttime'];
  $depart = $_POST['depart'];
  $name = $_POST['name'];
  $email = $_POST['email'];
  $telephone = $_POST['telephone'];
  
  $to = "me@mywebsite.com";
  $subject = "Recruitment Application";
  
  $message = $headers;
  $message .= "Name: " . $_POST["name"] . "\r\n";
  $message .= "E-mail: " . $_POST["email"] . "\r\n";
  
  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
  $headers .= "Reply-To: " . $_POST["email"] . "\r\n";
  $headers .= 'From: My Website &lt;application@mywebsite.com&gt;' . "\r\n";
  
  
  
  $message= "
  ";
  
  $url = stripslashes($_POST["url"]);
  if (!empty($url)) {
  header( 'Location: http://www.go-away-spam-robots.com' );
  exit();
  }
  
  if (!isset($warning)) {
  mail($to, $subject, $message, $headers);
  header( 'Location: http://www.mywebsite.co.uk/sent.php' );
  }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>I would like to make pretty much all the field compulsory so if a field is left empty (other than the hidden URL field), a warning message is displayed next to that field.</p>
  
  <p>Also I would like the file upload field to attach to the email that is sent to me and have the results come through to me in a table format.</p>
  
  <p>Can anyone help me get my form working?</p>
  
  <p>Thank you and I hope to hear from you!</p>
  
  <p>SM</p>