Contact form help

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:

  1. 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

  2. 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]

Attending
Yes    No

If no, please tell us your full names and click send:



Full names of those attending
Age
parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)
Email address
Special dietary requirements?

[/code]

[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);
?>

Mark and Stephanie's Wedding 2012

Thank you for RSVPing to our wedding! Love Stephanie & Mark

<?php } ?>[/php]

You can try something like this hope it helps you understand a bit more.
I made it in to one page for myself but you can split it up again to how you want it.
Try not to post your email address or anything else that you do not want others to know about in the php or code.

If it does not work post back what is wrong.

[php]

<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = ""; $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.

"; echo $error."

"; echo "Please go back and fix these errors.

"; 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.'); } $attendname1 = $_POST['attendname1']; $attendname2 = $_POST['attendname2']; $attendname3 = $_POST['attendname3']; $attendname4 = $_POST['attendname4']; $attendname5 = $_POST['attendname5']; // required $attending = $_POST['attending']; // required $notext = strip_tags($_POST['notext']); // not required $age1 = $_POST['age1']; $age2 = $_POST['age2']; $age3 = $_POST['age3']; $age4 = $_POST['age4']; $age5 = $_POST['age5']; // 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($attendname1)."\n"; $email_message .= "Age: ".clean_string($age1)."\n"; $email_message .= "Names: ".clean_string($attendname2)."\n"; $email_message .= "Age: ".clean_string($age2)."\n"; $email_message .= "Names: ".clean_string($attendname3)."\n"; $email_message .= "Age: ".clean_string($age3)."\n"; $email_message .= "Names: ".clean_string($attendname4)."\n"; $email_message .= "Age: ".clean_string($age4)."\n"; $email_message .= "Names: ".clean_string($attendname5)."\n"; $email_message .= "Age: ".clean_string($age5)."\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); } ?>
             <!-- include your own success html here -->
             <head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
             <title>Mark and Stephanie's Wedding 2012</title>
             <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
             <link rel="stylesheet" type="text/css" href="style.css"/>
             </head>
             <body>
             <div id="container">
             <div id="header">
             </div><div id="nav">
             <ul>
             <li>
             <a href="index.html">RSVP</a>
             </li>
             <li><a href="map.html">MAP AND DIRECTIONS</a></li>
             <li><a href="well.html">WISHING WELL</a></li>
             </ul>
             </div>
             <div id="main">
             <center><img src="images/rsvp.jpg" /><p>Thank you for RSVPing to our wedding! Love Stephanie & Mark</p></center>
    </div></div>
<?php if (!isset($_POST['attending']) && @$_POST['attending'] != 'Attending'){ ?>
Attending
Yes    No

If no, please tell us your full names and click send:




<?php } if (isset($_POST['attending']) && $_POST['attending'] == 'Not Attending'){ echo 'Sorry to hear your not coming to our wedding'; } if (isset($_POST['attending']) && $_POST['attending']== 'Attending'){ ?>

Full names of those attending

Age
Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Email address
Special dietary requirements?
<?php } ?> [/php]

It doesn’t work -

  1. When I click “No”, enter the names, click send, it seems to have sent because I get the confirmation message, but then I don’t receive any email.

  2. When I click “Yes”, enter all the data and click send, I get my error message. The only required data was whether they are attending or not I thought so I don’t know what the error is.

Also just wondering, I have a button that lets you add more names if you have more than 5 people attending. How will this be sent through?

I also just tried to use your code without splitting it up and this is what happens.
The screen only shows a button for Yes and No, no form below to select names and ages etc. (would be so much easier to show you the site or a screenshot…)

Clicking yes does nothing, clicking no allows you to enter the names of those not attending but once again when you click send I don’t receive the email.

I did change the part where you removed my email to have my hotmail address again. :confused:

I did test my code but I cannot send mail on my development server as I do not have it installed.

When you click yes and send it goes to the second section, which does work as I can test that part.
So maybe there is something wrong with your side or a bit was left ina comment.

But I wil test it again.

This works as one page

[php]

<?php function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } 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.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "RSVP to your wedding"; if(!isset($_POST['attending'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } // validation expected data exists $attendname1 = $_POST['attendname1']; if($_POST['attendname2'] != NULL){$attendname2 = $_POST['attendname2'];}else{$_POST['attendname2'] = 'empty';} if($_POST['attendname3'] != NULL){$attendname3 = $_POST['attendname3'];}else{$_POST['attendname3'] = 'empty';} if($_POST['attendname4'] != NULL){$attendname4 = $_POST['attendname4'];}else{$_POST['attendname4'] = 'empty';} if($_POST['attendname5'] != NULL){$attendname5 = $_POST['attendname5'];}else{$_POST['attendname5'] = 'empty';} // required $attending = $_POST['attending']; // required $notext = strip_tags($_POST['notext']); // not required $age1 = $_POST['age1']; if($_POST['age2']!= NULL){$age2 = $_POST['age2'];}else{$_POST['age2'] = 'empty';} if($_POST['age3']!= NULL){$age3 = $_POST['age3'];}else{$_POST['age3'] = 'empty';} if($_POST['age4']!= NULL){$age4 = $_POST['age4'];}else{$_POST['age4'] = 'empty';} if($_POST['age5']!= NULL){$age5 = $_POST['age5'];}else{$_POST['age5'] = 'empty';} // not required $email = $_POST['email']; // not required $comments = $_POST['comments']; // not required $email_message = "Someone has rsvp'd to your wedding!\n\n"; $email_message .= "Attending: ".clean_string($attending)."\n"; $email_message .= "Names of those not attending: ".clean_string($notext)."\n"; $email_message .= "Names: ".clean_string($attendname1)."\n"; $email_message .= "Age: ".clean_string($age1)."\n"; $email_message .= "Names: ".clean_string($attendname2)."\n"; $email_message .= "Age: ".clean_string($age2)."\n"; $email_message .= "Names: ".clean_string($attendname3)."\n"; $email_message .= "Age: ".clean_string($age3)."\n"; $email_message .= "Names: ".clean_string($attendname4)."\n"; $email_message .= "Age: ".clean_string($age4)."\n"; $email_message .= "Names: ".clean_string($attendname5)."\n"; $email_message .= "Age: ".clean_string($age5)."\n"; $email_message .= "Email address: ".clean_string($email)."\n"; $email_message .= "Special dietary requirements: ".clean_string($comments)."\n"; // create email headers $headers = 'From: SERVER <'.$email.'>'."\r\n".'Reply-To: '.$email."\r\n" .'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); } ?>
     <head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
   <title>Mark and Stephanie's Wedding 2012</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>

Thank you for RSVPing to our wedding! Love Stephanie & Mark

<?php if (!isset($_POST['attend'])){ ?>
Attending
Yes    No

If no, please tell us your full names and click send:

<?php } if (isset($_POST['attending']) && $_POST['attending'] == 'Not Attending'){ echo 'Sorry to hear your not coming to our wedding';

$email = ‘[email protected]’;
$email_to = "[email protected]";
$email_subject = “RSVP to your wedding not attedning”;
$email_message = clean_string($_POST[‘notext’]);
$headers = ‘From: Server <’.$email.’>’."\r\n".'Reply-To: '.$email."\r\n" .‘X-Mailer: PHP/’ . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
}
if (isset($_POST[‘attending’]) && $_POST[‘attending’] == ‘Attending’){
?>

Full names of those attending
Age
Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Email address
Special dietary requirements?
<?php } ?> [/php]

Posts the vars to another page to check they are correct [size=10pt]rsvp1.php[/size]
[php]

<?php if (isset($_POST['submit'])){ echo '
'.$_POST['email'].'
'; echo '
'.$_POST['attendname1'].'
'; echo '
'.$_POST['attendname2'].'
'; echo '
'.$_POST['attendname3'].'
'; echo '
'.$_POST['attendname4'].'
'; echo '
'.$_POST['attendname5'].'
'; echo '
'.$_POST['age1'].'
'; echo '
'.$_POST['age2'].'
'; echo '
'.$_POST['age3'].'
'; echo '
'.$_POST['age4'].'
'; echo '
'.$_POST['age5'].'
'; echo '
'.$_POST['comments'].'
'; }else{ echo 'nothing set'; } ?>

[/php]

[size=10pt]Post results[/size]

[email protected]
james
insert name
insert name
insert name
insert name
teen
Please Select
Please Select
Please Select
Please Select
cookies

Half way there.
The email for the Not Attending works now!

But when the site loads, the form to enter names, ages, email, diet does not show at all. (form name ‘follow’)

I’ll show you my entire code, I don’t understand what’s hiding it. I tried a few things and all I got was the same issues as before with the email not being received.
[php]

Mark and Stephanie's Wedding 2012
<?php function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } 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.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "RSVP to your wedding"; if(!isset($_POST['attending'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } // validation expected data exists $attendname1 = $_POST['attendname1']; if($_POST['attendname2'] != NULL){$attendname2 = $_POST['attendname2'];}else{$_POST['attendname2'] = 'empty';} if($_POST['attendname3'] != NULL){$attendname3 = $_POST['attendname3'];}else{$_POST['attendname3'] = 'empty';} if($_POST['attendname4'] != NULL){$attendname4 = $_POST['attendname4'];}else{$_POST['attendname4'] = 'empty';} if($_POST['attendname5'] != NULL){$attendname5 = $_POST['attendname5'];}else{$_POST['attendname5'] = 'empty';} // required $attending = $_POST['attending']; // required $notext = strip_tags($_POST['notext']); // not required $age1 = $_POST['age1']; if($_POST['age2']!= NULL){$age2 = $_POST['age2'];}else{$_POST['age2'] = 'empty';} if($_POST['age3']!= NULL){$age3 = $_POST['age3'];}else{$_POST['age3'] = 'empty';} if($_POST['age4']!= NULL){$age4 = $_POST['age4'];}else{$_POST['age4'] = 'empty';} if($_POST['age5']!= NULL){$age5 = $_POST['age5'];}else{$_POST['age5'] = 'empty';} // not required $email = $_POST['email']; // not required $comments = $_POST['comments']; // not required $email_message = "Someone has rsvp'd to your wedding!\n\n"; $email_message .= "Attending: ".clean_string($attending)."\n"; $email_message .= "Names of those not attending: ".clean_string($notext)."\n"; $email_message .= "Names: ".clean_string($attendname1)."\n"; $email_message .= "Age: ".clean_string($age1)."\n"; $email_message .= "Names: ".clean_string($attendname2)."\n"; $email_message .= "Age: ".clean_string($age2)."\n"; $email_message .= "Names: ".clean_string($attendname3)."\n"; $email_message .= "Age: ".clean_string($age3)."\n"; $email_message .= "Names: ".clean_string($attendname4)."\n"; $email_message .= "Age: ".clean_string($age4)."\n"; $email_message .= "Names: ".clean_string($attendname5)."\n"; $email_message .= "Age: ".clean_string($age5)."\n"; $email_message .= "Email address: ".clean_string($email)."\n"; $email_message .= "Special dietary requirements: ".clean_string($comments)."\n"; // create email headers $headers = 'From: SERVER <'.$email.'>'."\r\n".'Reply-To: '.$email."\r\n" .'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); } ?>
     <head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
   <title>Mark and Stephanie's Wedding 2012</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>

Thank you for RSVPing to our wedding! Love Stephanie & Mark

<?php if (!isset($_POST['attend'])){ ?>
Attending
Yes    No

If no, please tell us your full names and click send:

<?php } if (isset($_POST['attending']) && $_POST['attending'] == 'Not Attending'){ echo 'Sorry to hear your not coming to our wedding';

$email = ‘[email protected]’;
$email_to = "[email protected]";
$email_subject = “RSVP to your wedding not attedning”;
$email_message = clean_string($_POST[‘notext’]);
$headers = ‘From: Server <’.$email.’>’."\r\n".'Reply-To: '.$email."\r\n" .‘X-Mailer: PHP/’ . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
}
if (isset($_POST[‘attending’]) && $_POST[‘attending’] == ‘Attending’){
?>

Full names of those attending
Age
Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Email address
Special dietary requirements?
<?php } ?>
[/php]

I think its because I added code to do a simular thing to you but I did not have the java code because java sucks.

The code I made was to only show the form if they are coming but your java hides the submit button from you.

[php]

Mark and Stephanie's Wedding 2012
<?php function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } 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.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "RSVP to your wedding"; if(!isset($_POST['attending'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } // validation expected data exists $attendname1 = $_POST['attendname1']; $attendname2 = $_POST['attendname2']; $attendname3 = $_POST['attendname3']; $attendname4 = $_POST['attendname4']; $attendname5 = $_POST['attendname5'];

// required
$attending = $_POST[‘attending’];
// required
$notext = strip_tags($_POST[‘notext’]);
// not required
$age1 = $_POST[‘age1’];
$age2 = $_POST[‘age2’];
$age3 = $_POST[‘age3’];
$age4 = $_POST[‘age4’];
$age5 = $_POST[‘age5’];

// not required
$email = $_POST[‘email’];
// not required
$comments = $_POST[‘comments’];
// not required
$email_message = “Someone has rsvp’d to your wedding!\n\n”;
$email_message .= “Attending: “.clean_string($attending).”\n”;
$email_message .= “Names: “.clean_string($attendname1).” - Age: “.clean_string($age1).”\n”;
$email_message .= “Names: “.clean_string($attendname2).” - Age: “.clean_string($age2).”\n”;
$email_message .= “Names: “.clean_string($attendname3).” - Age: “.clean_string($age3).”\n”;
$email_message .= “Names: “.clean_string($attendname4).” - Age: “.clean_string($age4).”\n”;
$email_message .= “Names: “.clean_string($attendname5).” - Age: “.clean_string($age5).”\n”;
$email_message .= “Email address: “.clean_string($email).”\n”;
$email_message .= “Special dietary requirements: “.clean_string($comments).”\n”;
// create email headers
$headers = ‘From: SERVER <’.$email.’>’."\r\n".'Reply-To: '.$email."\r\n" .‘X-Mailer: PHP/’ . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
}
?>

     <head>
Mark and Stephanie's Wedding 2012

Thank you for RSVPing to our wedding! Love Stephanie & Mark

<?php if (!isset($_POST['attend'])){ ?>
Attending
Yes    No

If no, please tell us your full names and click send:

<?php } if (isset($_POST['attending']) && $_POST['attending'] == 'Not Attending'){ $email = '[email protected]'; $email_to = "[email protected]"; $email_subject = "RSVP to your wedding not attedning"; $email_message = "Names of those not attending: ".clean_string($_POST['notext']); $headers = 'From: Server <'.$email.'>'."\r\n".'Reply-To: '.$email."\r\n" .'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers);

echo ‘Sorry to hear your not coming to our wedding ‘.clean_string($_POST[‘notext’]).’.’;
}
if (isset($_POST[‘attending’]) && $_POST[‘attending’] == ‘Attending’){
?>

Full names of those attending
Age
Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Email address
Special dietary requirements?
<?php } ?>
[/php]

Tried it, the Yes form appears now but when I fill out the form and click send, I get my own error message.
"We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.

We are sorry, but there appears to be a problem with the form you submitted.

Please go back and fix these errors."

If I leave it with your code sending it to rsvp1.php the results post through. Huh?!

I think I may just give up and have it so that the user enters the number of adults, children, babies etc in a text field.

Just add another input to the second form and remove the rsvp1.php from the action value, as you want it to post to itself

[php]

[/php]

so it will be like this
[php]

[/php]

So after a lot of meddling it works! i can now receive an email whether someone clicks Yes or No.

The only problems left now are

  • “Add another name” button works, but these extra names and ages are not sent with the form. Is there a way to do this or should I just have a textbox where they can manually enter extra info?

  • The success html for the Yes appears when the page loads without a form having to be submitted. Is there a way to have a one line message like you’ve done for when someone that clicks No (in php)? I tried a few things but they didn’t work. At the moment if I remove the success html and click submit the page just reloads and displays both the No form and Yes form, so users may not think their form has been submitted (when it actually has).

If not, no dramas, I am happy with how the form works now and thank you so much for all the help you gave me.

When you click add another name what are the names of the text areas ?
That part does not work for me so I do not know the names of the text areas.

The message you can split the php from the form and put it in the another page like your success.php and then use something like the code below to show your success html message.
[php]
header(‘Location: success.html’);
[/php]

or just do a little bit of code around the mail code.
[php]if (isset(submit)){

if (mail($email_to, $email_subject, $email_message, $headers)){
echo ‘Thank you for coming and hope you get a great big pressie from you clean_string($attendname1).’;’;
}else{
There seeems to have been a problem sending the message please try again.
}

        }
        ?>   

[/php]

The problem with adding more is you will have to add more vars and post vars to the code to match which is not hard just follow the ones that are already there.

OK I quickly adjusted it for you.

[php]

Mark and Stephanie's Wedding 2012
<?php function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } 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.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "RSVP to your wedding"; if(!isset($_POST['attending'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } // validation expected data exists $attendname1 = $_POST['attendname1']; $attendname2 = $_POST['attendname2']; $attendname3 = $_POST['attendname3']; $attendname4 = $_POST['attendname4']; $attendname5 = $_POST['attendname5'];

// required
$attending = $_POST[‘attending’];
// required
if(isset($_POST[‘notext’])){
$notext = strip_tags($_POST[‘notext’]);
}
// not required
$age1 = $_POST[‘age1’];
$age2 = $_POST[‘age2’];
$age3 = $_POST[‘age3’];
$age4 = $_POST[‘age4’];
$age5 = $_POST[‘age5’];

// not required
$email = $_POST[‘email’];
// not required
$comments = $_POST[‘comments’];
// not required
$email_message = “Someone has rsvp’d to your wedding!\n\n”;
$email_message .= “Attending: “.clean_string($attending).”\n”;
$email_message .= “Names: “.clean_string($attendname1).” - Age: “.clean_string($age1).”\n”;
$email_message .= “Names: “.clean_string($attendname2).” - Age: “.clean_string($age2).”\n”;
$email_message .= “Names: “.clean_string($attendname3).” - Age: “.clean_string($age3).”\n”;
$email_message .= “Names: “.clean_string($attendname4).” - Age: “.clean_string($age4).”\n”;
$email_message .= “Names: “.clean_string($attendname5).” - Age: “.clean_string($age5).”\n”;
$email_message .= “Email address: “.clean_string($email).”\n”;
$email_message .= “Special dietary requirements: “.clean_string($comments).”\n”;
// create email headers
$headers = ‘From: SERVER <’.$email.’>’."\r\n".'Reply-To: '.$email."\r\n" .‘X-Mailer: PHP/’ . phpversion();

       # mail($email_to, $email_subject, $email_message, $headers);

}
?>

     <head>
Mark and Stephanie's Wedding 2012

Thank you for RSVPing to our wedding! Love Stephanie & Mark

<?php if (isset($_POST['submit'])){ if (mail($email_to, $email_subject, $email_message, $headers)){ echo '

Thank you for coming and hope you get a great big pressie from you '.clean_string($attendname1).'.

'; }else{ echo '

There seeems to have been a problem sending the message please try again.

'; } } if (!isset($_POST['attend']) && !isset($_POST['submit']) ){ ?>
Attending
Yes    No

If no, please tell us your full names and click send:

<?php } if (isset($_POST['attending']) && $_POST['attending'] == 'Not Attending'){ $email = '[email protected]'; $email_to = "[email protected]"; $email_subject = "RSVP to your wedding not attedning"; $email_message = "Names of those not attending: ".clean_string($_POST['notext']); $headers = 'From: Server <'.$email.'>'."\r\n".'Reply-To: '.$email."\r\n" .'X-Mailer: PHP/' . phpversion(); if(mail($email_to, $email_subject, $email_message, $headers)){

echo ‘Sorry to hear your not coming to our wedding ‘.clean_string($_POST[‘notext’]).’.’;
} else {echo ‘please try again the message was not sent’;}
}

if (isset($_POST[‘attending’]) && $_POST[‘attending’] == ‘Attending’ && !isset($_POST[‘submit’])){
?>

Full names of those attending
Age
Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Please Select parent (over 18yrs) Teenager (12yrs - 18yrs) Child (2yrs - 12yrs) Baby (needs a highchair)

Email address
Special dietary requirements?
<?php } ?>
[/php]

This java script you should download and add to your server because google server might be down or not responding or just laggy.

https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

The code I’m using to add another name is this

[code]var counter = 1;
var limit = 12
function addInput(divName){
if (counter == limit) {
alert(“You have reached the limit of adding " + counter + " names”);
}
else {
var newdiv = document.createElement(‘div’);
newdiv.innerHTML = "
parent (over 18yrs)Teenager (12yrs - 18yrs)Child (2yrs - 12yrs)Baby (needs a highchair)";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}

[/code]

If i just start adding more vars and posts, how does the code know that when the button is pressed the next row of fields should be named attendname6 and age6, and then attendname7 and age7 and so on?

With the code counter you are going to make to count the numbers of the new input fields.
The new input field names are almost the same but has a _ between the name and the number.

attendname_1
attendname_2
attendname_3
so on

[php]
var counter = 1;
var limit = 12
function addInput(divName){
if (counter == limit) {
alert(“You have reached the limit of adding " + counter + " names”);
}else{
var newdiv = document.createElement(‘div’);
newdiv.innerHTML = "

Please Selectparent (over 18yrs)Teenager (12yrs - 18yrs)Child (2yrs - 12yrs)Baby (needs a highchair)

";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}

[/php]

You’re a genius! Thank you so much for your help.

I would not go that far I know a little.
Your welcome.

I did notice one thing that was if you press submit on the first part yes or no it submits and goes no where, you might want to fix that with a [size=10pt]checked[/size] on the yes radio button to start with.

Sponsor our Newsletter | Privacy Policy | Terms of Service