Need help with PHP form with checkboxes, radio buttons and file attachment

Hi guys,

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!

Here is the HTML of contact.php:

<form action="" method="post" name="contact" id="contact">

    <p>Job Title:*<br />
    <input name="position" type="text" /></p>

	<p>Nationality:*<br />
	<select name="nationality">
      <option value="">-- select one --</option>
      <option value="Afghan">Afghan</option>
      <option value="Albanian">Albanian</option>
      <option value="Algerian">Algerian</option>
      <option value="Zambian">Zambian</option>
      <option value="Zimbabwean">Zimbabwean</option>

    <p>Which country are you currently living in?*<br />
	<select name="country">
    <option value="">-- select one --</option>
    <option value="United Kingdom">United Kingdom</option>
    <option value="Afghanistan">Afghanistan</option>
    <option value="Africa">Africa</option>
    <option value="Zambia">Zambia</option>
    <option value="Zimbabwe">Zimbabwe</option>

    <label class="radio" for="checkRight">Yes/No question?</label><br />
    <input class="radio" type="radio" name="right" value="Yes" /> Yes
    <input class="radio" type="radio" name="right" value="No" /> No
    <input class="radio" type="radio" name="right" value="N/A" /> Not applicable

    <p>Yes/No question?<br />
    <select name="continue">
    <option value="">-- select one --</option>
    <option value="Yes">Yes</option>
    <option value="No">No</option>

    <p>Select your resorts:<br />
    Resort 1<input name="res1" type="checkbox" value="Resort 1" />
    Resort 2<input name="res2" type="checkbox" value="Resort 2" />
    Resort 3<input name="res3" type="checkbox" value="Resort 3" />
    Resort 4<input name="res4" type="checkbox" value="Resort 4" />
    Resort 5<input name="res5" type="checkbox" value="Resort 5" />
    Resort 6<input name="res6" type="checkbox" value="Resort 6" />

    <p>Don't send form unless this is checked:* <input type="checkbox" name="parttime" value="Yes" /></p>

    <p>Date of arrival: <input name="arrive" id="datepick" /><br />
    Date of departure: <input name="depart" id="datepick2" /></p>

    <script type="text/javascript" src="assets/scripts/datepickr/datepickr.js"></script>
    <link href="assets/scripts/datepickr/datepickr.css" rel="stylesheet">

    <script type="text/javascript">
    new datepickr('datepick');
    new datepickr('datepick2', {

    <p>Name:*<br />
    <input name="name" type="text" /></p>

    <p>E-mail:*<br />
    <input name="email" type="text" /></p>

    <p>Telephone:*<br />
    <input name="telephone" type="text" class="ctextField" /></p>

    <p>Upload CV (Word of PDF formats only):<br />
    <input type="file" name="cv" class="textfield"></p>

    <p><input name="submit" value="Submit Enquiry" class="submitButton" type="submit" /><div style="visibility:hidden; width:1px; height:1px"><input name="url" type="text" size="45" id="url" /></div></p>


By the way, the date boxes work so excuse the Javascript in there!

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.

Below is where I’m at with the PHP which is placed above the header of contact.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 = "";
$subject = "Recruitment Application";

$message = $headers;
$message .= "Name: " . $_POST["name"] . "\\r\
$message .= "E-mail: " . $_POST["email"] . "\\r\

$headers  = "MIME-Version: 1.0\\r\
$headers .= "Content-type: text/html; charset=iso-8859-1\\r\
$headers .= "Reply-To: " . $_POST["email"] . "\\r\
$headers .= 'From: My Website <>' . "\\r\

$message= "

$url = stripslashes($_POST["url"]);
if (!empty($url)) {
header( 'Location:' );

if (!isset($warning)) {
mail($to, $subject, $message, $headers);
header( 'Location:' );



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.

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.

Can anyone help me get my form working?

Thank you and I hope to hear from you!


Notice anything wrong with this line?

$message= "

You basically are disregarding anything else already assigned to this variable above.

$message = $headers;
$message .= "Name: " . $_POST["name"] . "\\r\
$message .= "E-mail: " . $_POST["email"] . "\\r\

I don’t think you should assign the variable $headers to the $message and POST[‘keys’] should be in single quotes.