Hi I’m making a website where users can RSVP to a wedding invitation.
I know very little php and usually rely on google searches and tutorials to get by, but this time I’m unsure of what to search for.
Ideally I want my form to function like this:
-
If a user is Not Attending, they click “No” and enter their names. This information only is then sent to me:
Attending: Not Attending
Names of those not attending: John and Jane Smith -
If a user is Attending, they click “Yes” and fill out the rest of the form. I would want the email to look something like this:
Attending: Attending
Names of those attending:
John Smith - Parent (over 18yrs)
Jane Smith - Teen (12yrs - 18yrs)
Sally Smith - Baby (needs a highchair)
Email address: [email protected]
Special dietary requirements: No red meat.
The problem I’m having is getting the information from each name of those attending to display and show their corresponding age. I’ve only ever done simple forms with radio buttons and text fields.
Any help is appreciated. Code is below. On my actual site I’ve got “Adult” where I’ve now put “Parent” because the forum didn’t like it.
[code]
If no, please tell us your full names and click send:
[php]<?php
if(isset($_POST[‘email’])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "RSVP to your wedding";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['attending'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$attendname = $_POST['attendname']; // required
$attending = $_POST['attending']; // required
$notext = $_POST['notext']; // not required
$parent = $_POST['parent']; // not required
$teen = $_POST['teen']; // not required
$child = $_POST['child']; // not required
$baby = $_POST['baby']; // not required
$email = $_POST['email']; // not required
$comments = $_POST['comments']; // not required
$email_message = "Someone has rsvp'd to your wedding!\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Attending: ".clean_string($attending)."\n";
$email_message .= "Names of those not attending: ".clean_string($notext)."\n";
$email_message .= "Names: ".clean_string($attendname)."\n";
$email_message .= "Age: ".clean_string($age)."\n";
$email_message .= "Email address: ".clean_string($email)."\n";
$email_message .= "Special dietary requirements: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>