...

View Full Version : Contact Form issues



sarahm
01-24-2012, 05:25 AM
Hey, I'm new to coding, and I'm having some issues with a contact form on a site I'm working on. I've tested it out a few times, and for some reason it's posting blank fields even when the fields are filled in, so the email i'm receiving looks like this:

From:
E-mail:
Character:
Party Package:
Age Range:
Childs Name:
Childs Age:
Birthday:
Party Date:
Party Time:
Guests:
Message:

this is what i have for the php code:



<?php

$field_name = $_POST ['first name'] ['last name'];
$field_email = $_POST['email'];
$field_character = $_POST['character'];
$field_partypackage = $_POST['party package'] ;
$field_agerange = $_POST['age range'];
$field_childname = $_POST['childname'];
$field_childage = $_POST['childage'];
$field_birthday = $_POST['bmonth'] ['bday'] ['byr'];
$field_partydate = $_POST['pmonth'] ['pday'] ['pyr'];
$field_partytime = $_POST['partytimehr']['partytimemin']['AMPM'];
$field_guests = $_POST['guests'];
$field_message = $_POST['message'];

$mail_to = 'princessagency@mail.com';
$subject = 'Princess Agency Contact Form Submitted'.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Character: '.$field_character."\n";
$body_message .= 'Party Package: '.$field_partypackage."\n";
$body_message .= 'Age Range: '.$field_agerange."\n";
$body_message .= 'Childs Name: '.$field_childname."\n";
$body_message .= 'Childs Age: '.$field_childage."\n";
$body_message .= 'Birthday: '.$field_birthday."\n";
$body_message .= 'Party Date: '.$field_partydate."\n";
$body_message .= 'Party Time: '.$field_partytime."\n";
$body_message .= 'Guests: '.$field_guests."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";



$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to princessagency@mail.com');
window.location = 'index.html';
</script>
<?php
}
?>


and here's the form's html:


<form action="contact.php" method="post" enctype="text/plain">

Name:<br />
<input type="text" name="first name" value="first name" size="11" />
<input type="text" name="last name" value="last name" size="11" />
<br /><br/>
E-mail:<br />
<input type="text" name="mail" value="email" /><br /><br/>
Character:<br/>
<select name="character">
<option value="Cinderella">Cinderella</option>
<option value="Snow White">Snow White</option>
<option value="Aurora">Aurora (Sleeping Beauty)</option>
<option value="Tinkerbelle">Tinkerbelle</option>
<option value="Ariel">Ariel (Little Mermaid)</option>
<option value="Jasmine">Jasmine</option>
</select><br/><br/>
Party Package:<br/>
<select name="party package">
<option value="1/2 Hour">1/2 Hour Party $80</option>
<option value="1 Hour">1 Hour Party $150</option>
<option value="1.5 Hour">1.5 Hour Party $180</option>
<option value="2 Hour">2 Hour Party $210</option>
<option value="specialty">Specialty Party</option>
</select><br/><br/>
Party's Age Range:<br/>
<select name="age range">
<option value="under 3">0-3 years</option>
<option value="3 to 5">3-5 years</option>
<option value="5 to 7">5-7 years</option>
<option value="7 and up">7 and up</option>
<option value="all ages">all ages</option>
</select><br/><br/>
Child's Name:<br/>
<input type="text" name="childname" value="child's name" /><br/><br/>



Child's Age:<br/>

<input type="text" name="childage" value="child's age" /><br/><br/>

Child's Birthday:<br/>
<input type="text" name="bmonth" maxlength="2" size="3" value="MM" />
<input type="text" name="bday" maxlength="2" size="3" value="DD" />
<input type="text" name="byr" maxlength="4" size="5" value="YYYY" />
<br/><br/>
Party Date:<br/>
<input type="text" name="pmonth" maxlength="2" size="3" value="MM" />
<input type="text" name="pday" maxlength="2" size="3" value="DD" />
<input type="text" name="pyr" maxlength="4" size="5" value="YYYY" />
<br/><br/>
Party Time:<br/>
<input type="text" name="partytimehr" maxlength="2" size="2" value="11" /> :
<input type="text" name="partytimemin" maxlength="2" size="2" value="00" />
<select name="AMPM">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select><br/><br/>
Expected Number of Guests <br/>(children only):<br />
<input type="text" name="guests" size="5" maxlength="4" /><br /><br/>

Your Message:<br />
<textarea rows="10" cols="35" name:"message" value:"message">How can we make your party magical? Does the party have a theme? Does the Birthday girl or boy have a favorite game or activity? Let us know, so we can make your party one of a kind! </textarea>
<br /><br />
<input type="submit" value= "send">


</form>


here's where everything is published: http://smsk.site90.com/contact.html

let me know if you can see what I'm doing wrong here.... I'm going crazy.

Thanks!

BluePanther
01-24-2012, 06:17 AM
Hey, I'm new to coding, and I'm having some issues with a contact form on a site I'm working on. I've tested it out a few times, and for some reason it's posting blank fields even when the fields are filled in, so the email i'm receiving looks like this:

From:
E-mail:
Character:
Party Package:
Age Range:
Childs Name:
Childs Age:
Birthday:
Party Date:
Party Time:
Guests:
Message:

this is what i have for the php code:



<?php

$field_name = $_POST ['first name'] ['last name'];
$field_email = $_POST['email'];
$field_character = $_POST['character'];
$field_partypackage = $_POST['party package'] ;
$field_agerange = $_POST['age range'];
$field_childname = $_POST['childname'];
$field_childage = $_POST['childage'];
$field_birthday = $_POST['bmonth'] ['bday'] ['byr'];
$field_partydate = $_POST['pmonth'] ['pday'] ['pyr'];
$field_partytime = $_POST['partytimehr']['partytimemin']['AMPM'];
$field_guests = $_POST['guests'];
$field_message = $_POST['message'];

$mail_to = 'princessagency@mail.com';
$subject = 'Princess Agency Contact Form Submitted'.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Character: '.$field_character."\n";
$body_message .= 'Party Package: '.$field_partypackage."\n";
$body_message .= 'Age Range: '.$field_agerange."\n";
$body_message .= 'Childs Name: '.$field_childname."\n";
$body_message .= 'Childs Age: '.$field_childage."\n";
$body_message .= 'Birthday: '.$field_birthday."\n";
$body_message .= 'Party Date: '.$field_partydate."\n";
$body_message .= 'Party Time: '.$field_partytime."\n";
$body_message .= 'Guests: '.$field_guests."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";



$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to princessagency@mail.com');
window.location = 'index.html';
</script>
<?php
}
?>


and here's the form's html:


<form action="contact.php" method="post" enctype="text/plain">

Name:<br />
<input type="text" name="first name" value="first name" size="11" />
<input type="text" name="last name" value="last name" size="11" />
<br /><br/>
E-mail:<br />
<input type="text" name="mail" value="email" /><br /><br/>
Character:<br/>
<select name="character">
<option value="Cinderella">Cinderella</option>
<option value="Snow White">Snow White</option>
<option value="Aurora">Aurora (Sleeping Beauty)</option>
<option value="Tinkerbelle">Tinkerbelle</option>
<option value="Ariel">Ariel (Little Mermaid)</option>
<option value="Jasmine">Jasmine</option>
</select><br/><br/>
Party Package:<br/>
<select name="party package">
<option value="1/2 Hour">1/2 Hour Party $80</option>
<option value="1 Hour">1 Hour Party $150</option>
<option value="1.5 Hour">1.5 Hour Party $180</option>
<option value="2 Hour">2 Hour Party $210</option>
<option value="specialty">Specialty Party</option>
</select><br/><br/>
Party's Age Range:<br/>
<select name="age range">
<option value="under 3">0-3 years</option>
<option value="3 to 5">3-5 years</option>
<option value="5 to 7">5-7 years</option>
<option value="7 and up">7 and up</option>
<option value="all ages">all ages</option>
</select><br/><br/>
Child's Name:<br/>
<input type="text" name="childname" value="child's name" /><br/><br/>



Child's Age:<br/>

<input type="text" name="childage" value="child's age" /><br/><br/>

Child's Birthday:<br/>
<input type="text" name="bmonth" maxlength="2" size="3" value="MM" />
<input type="text" name="bday" maxlength="2" size="3" value="DD" />
<input type="text" name="byr" maxlength="4" size="5" value="YYYY" />
<br/><br/>
Party Date:<br/>
<input type="text" name="pmonth" maxlength="2" size="3" value="MM" />
<input type="text" name="pday" maxlength="2" size="3" value="DD" />
<input type="text" name="pyr" maxlength="4" size="5" value="YYYY" />
<br/><br/>
Party Time:<br/>
<input type="text" name="partytimehr" maxlength="2" size="2" value="11" /> :
<input type="text" name="partytimemin" maxlength="2" size="2" value="00" />
<select name="AMPM">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select><br/><br/>
Expected Number of Guests <br/>(children only):<br />
<input type="text" name="guests" size="5" maxlength="4" /><br /><br/>

Your Message:<br />
<textarea rows="10" cols="35" name:"message" value:"message">How can we make your party magical? Does the party have a theme? Does the Birthday girl or boy have a favorite game or activity? Let us know, so we can make your party one of a kind! </textarea>
<br /><br />
<input type="submit" value= "send">


</form>


here's where everything is published: http://smsk.site90.com/contact.html

let me know if you can see what I'm doing wrong here.... I'm going crazy.

Thanks!

Your PHP is wrong when assigning the fields. I'm guessing you want first and last names to be concatenated for the mail?
The way you're accessing last name is wrong. You're accessing it as if it's an array index of first name, when in fact it's an index of POST. In other words, it should be


// . concatenates strings in PHP (appends one string onto another)
$field_name = $_POST['first name'].$_POST['last name'];

// or, for style
$field_name = $_POST'first name'].' '.$_POST['last name'];

You shouldn't use spaces in index names, or any pointer or variable in fact. I don't think it'll break anything in PHP, but it's just not great practise.

sarahm
01-24-2012, 09:51 PM
Thanks for your help! I made the alterations, but the form is still coming in blank... its like its not collecting the input from the fields... I don't know what's happening :/

BluePanther
01-24-2012, 09:53 PM
Thanks for your help! I made the alterations, but the form is still coming in blank... its like its not collecting the input from the fields... I don't know what's happening :/

Do a var_dump of $_POST before setting your variables and make sure you're getting the indexes right.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum