Im pretty new to php language. Currently Im working on making a form and let user click submit and the output will be sent to my email(using phpmailer).
For now all working OK, but I just want to make a minor tweak where if user answer YES for the radio button, then the user need to check at least 1 checkbox in order for the form to process, whereas if the user answer NO for the radio button, there is no error shown if they dont check the checkbox. Need some idea on how to tweak the code to make it like that.
The form HTML
<div class="form-group">
<p>Have you worn contact Lens before?</p>
<input type="radio" name="lenses" value="Yes"/> Yes<br>
<input type="radio" name="lenses" value="No"/> No<br>
</div>
<div class="form-group">
<p>If yes, which type of disposable contact lens have you worn before?</p>
<input type="checkbox" name="disposable_lens[]" value="Monthly"/> Monthly<br>
<input type="checkbox" name="disposable_lens[]" value="Daily Disposables"/> Daily Disposables<br>
</div>
The PHP
if(isset($_POST["submit"]))
{
if(empty($_POST["lenses"]))
{
$error .= '<p><label class="text-danger">Lenses is required</label></p>';
}
else
{
$lenses = clean_text($_POST["lenses"]);
}
if(empty($_POST["disposable_lens"]))
{
$error .= '<p><label class="text-danger">Disposable_lens is required</label></p>';
}
else
{
$disposable_lens = array_map('clean_text', $_POST["disposable_lens"]);
And this is the phpmailer body message in case you guys want to see
$mail->Body = join('', array(
"Outlet: ",
$_POST['outlet'],
"<br/>",
"Full Name: ",
$_POST['fullname'],
"<br/>",
"Email Address: ",
$_POST['email'],
"<br/>",
"Phone Number:",
$_POST['contact_no'],
"<br/>",
"Have you worn contact lens before?: ",
$_POST['lenses'],
"<br/>",
"If yes, which type of disposable contact lens have you worn before?: ",
join(', ', $_POST['disposable_lens']),
"<br/>",
"Appointment Date ",
$_POST['date'],
"<br/>",
"Appointment Time ",
$_POST['time']
));
Aucun commentaire:
Enregistrer un commentaire