How do I add an element to my PHP form?

Jamie F

New member
Based on the below I want to add a drop-down menu. What changes do i need to make to the hTML and the PHP file so this will work?


Below is my form HTML:
<form id="contact-form" action="process.php" method="post">
<fieldset>
<div class="float-left">
<label for="Name">Full Name</label>
<input id="Name" type="text" name="FullName" />
<label for="Email">Email Address</label>
<input id="Email" type="text" name="EmailAddress" />
<label for="Phone">Phone Number</label>
<input id="Phone" type="text" name="Phone" />

</select>
</div>
<div class="float-right">
<label for="Message">Message</label>
<textarea id="Message" rows="10" cols="10" name="Enquiry"></textarea>
<p class="contact-success"><strong>Thank you</strong> for your enquiry. We will be in touch shortly.</p>
<p class="contact-error"><strong>Error</strong>, Please fill out all required fields.</p>
<button type="submit">Send Enquiry</button>
</div>
<div class="clear"></div>

and below is my PHP File:
<?php

function valid_email($Email)
{
//new regex, didn't give me any errors...might be a bit more exact
if (ereg('^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$', $Email) != false)
return true;
else
return false;
}

function sendEmail($email){
return mail ($email['to'], $email['subject'], $email['message'], $email['headers']);
}

// get posted data into local variables
$FullName = trim(stripslashes($_POST['FullName']));
$EmailAddress = trim(stripslashes($_POST['EmailAddress']));
$Phone = trim(stripslashes($_POST['Phone']));
$Enquiry = trim(stripslashes($_POST['Enquiry']));

//setup email
$email['to'] = 'myemailaddress';
$email['subject'] = "Enquiry from: {$EmailAddress}";
$email['headers'] = "From: Lift Off LCP Enquiry <{$EmailAddress}>\r\n";
// prepare email body text
$email['message'] = "Full Name: {$FullName}\n\n";
$email['message'] .= "Email: {$EmailAddress}\n\n";
$email['message'] .= "Phone: {$Phone}\n\n";
$email['message'] .= "Enquiry: {$Enquiry}\n\n";

//sendEmail($email);

// validation
if (valid_email($EmailAddress) && $FullName != "" && $Enquiry != "") { //if return is true...
sendEmail($email);
echo 0; //Success
}else { //otherwise
echo 1; //Error
}

?>
 
Back
Top