I have a form that takes in a few fields.
Upon entering all fields, email will be sent to me with the details.
If any fields are missing, the form will redirect to fail.html file.
If I select at least one of the select values, I get redirected to the fail.html page.
However, the issue is that if I don't select any of the select multiple dropdown list, I get this error.
Warning: implode() [function.implode]: Invalid arguments passed in /home/mydomain/public_html/iComm/contact.php on line 6
Warning: Cannot modify header information - headers already sent by (output started at /home/mydomain/public_html/iComm/contact.php:6) in /home/mydomain/public_html/iComm/contact.php on line 19
This is the HTML.
<div id="form">
<form method="post" action="contact.php">
<input type="text" name="fullName" placeholder="Full Name">
<input type="email" name="email" placeholder="Email Address">
<input type="text" name="number" placeholder="Phone">
<div class="styled-select">
<select multiple="multiple" name="choices[]">
<option style="color:grey";" value="Fri 8AM">Fri 20 Mar 8PM</option>
<option style="color:grey";" value="Sat 8AM">Sat 21 Mar 8AM</option>
<option style="color:grey";" value="Sat 2PM">Sat 21 Mar 2PM</option>
<option style="color:grey";" value="Sat 8PM">Sat 21 Mar 8PM</option>
<option style="color:grey";" value="Sun 8AM">Sun 22 Mar 8AM</option>
</select>
</div>
<input type="submit" class="button" value="Sign Up">
</form>
This is the PHP file.
$fullName= $_POST['fullName'];
$email=$_POST['email'];
$tel=$_POST['number'];
$choice = implode(',', $_POST['choices']);
if(!empty($fullName) && !empty($email) && !empty($tel) && !empty($choice)){
$to = 'm@gmail.com';
$subject = '2015';
$msg = "$fullName is keen to join. His/her email address is $email and number is $tel. He/She chose $choice.";
mail($to, $subject, $msg, 'From: ' .$email);
header("Location: success.html");
}
else{
if(empty($fullName) || empty($email) || empty($tel) || empty($choice)){
header("Location: fail.html");
}
}
?>