Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

contact form not returning all info

General discussions related to php

Moderators: macek, egami, gesf

contact form not returning all info

Postby dirtmcgirt » Tue Oct 23, 2012 12:07 pm

Hello,
i have been at this all day!
I am trying to customize a contact form which had originally 4 fields. I have added more fields, but the email sent only includes a maximum of 4, regardless whether they are the new ones or the originals, or a mix of both, only 4 fields are sent. Here is my java script and php code if anyone can help me out.
thanks alot!

java script:

$(document).ready(function(){


$("#error").hide();
$("#success").hide();


$("#contactForm #submit").click(function() {
$("#error").hide();



var prenom = $("input#prenom").val();
if(prenom == ""){
$("#error").fadeIn().text("Prénom requis.");
$("input#prenom").focus();
return false;
}
var nom = $("input#nom").val();
if(nom == ""){
$("#error").fadeIn().text("Nom requis.");
$("input#nom").focus();
return false;
}

var jour = $("input#jour").val();
if(jour == ""){
$("#error").fadeIn().text("Date de naissance requise.");
$("input#jour").focus();
return false;
}
var mois = $("input#mois").val();
if(mois == ""){
$("#error").fadeIn().text("Date de naissance requise.");
$("input#mois").focus();
return false;
}
var annee = $("input#annee").val();
if(annee == ""){
$("#error").fadeIn().text("Date de naissance requise.");
$("input#annee").focus();
return false;
}

var email = $("input#email").val();
if(email == ""){
$("#error").fadeIn().text("Courriel requis");
$("input#email").focus();
return false;
}



var sendMailUrl = $("#sendMailUrl").val();

var to = $("#to").val();
var from = $("#from").val();
var subject = $("#subject").val();

// data string
var dataString = 'prenom='+ prenom
+ '&nom=' + nom
+ '&jour=' + jour
+ '&mois=' + mois
+ '&annee=' + annee
+ '&email=' + email
+ '&to=' + to
+ '&from=' + from
+ '&subject=' + subject;
// ajax
$.ajax({
type:"POST",
url: sendMailUrl,
data: dataString,
success: success()
});
});
function success(){
$("#success").fadeIn();
//$("#contactForm").fadeOut();

}

return false;
});



php:

<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );

$from = $_POST['email'];

//data
$msg = "PRÉNOM: " .$_POST['prenom'] ."<br>\n";
$msg = "NOM: " .$_POST['nom'] ."<br>\n";
$msg .= "JOUR: " .$_POST['jour'] ."<br>\n";
$msg .= "MOIS: " .$_POST['mois'] ."<br>\n";
$msg .= "ANNEE: " .$_POST['annee'] ."<br>\n";
$msg .= "COURRIEL: " .$_POST['email'] ."<br>\n";


$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;

foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}

?>
<?php echo "Xy6Hy";?>:
dirtmcgirt
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Oct 23, 2012 11:55 am

Re: contact form not returning all info

Postby seandisanti » Tue Oct 23, 2012 12:54 pm

Code: Select all
//data
$msg = "PRÉNOM: " .$_POST['prenom'] ."<br>\n";
$msg = "NOM: " .$_POST['nom'] ."<br>\n";
$msg .= "JOUR: " .$_POST['jour'] ."<br>\n";
$msg .= "MOIS: " .$_POST['mois'] ."<br>\n";
$msg .= "ANNEE: " .$_POST['annee'] ."<br>\n";
$msg .= "COURRIEL: " .$_POST['email'] ."<br>\n";

you're losing the value in PRÉNOM immediately, because you're assigning right over it on the next line. beyond that, if you could include the html for your form it may help
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: contact form not returning all info

Postby dirtmcgirt » Wed Oct 24, 2012 5:01 am

Hey thanks for your help, not sure what i have to change so that i'm not assigning over the PRÉNOM value, but here is my html:

<form id="contactForm" name="listForm" action="#" method="post">
<fieldset>

<div>
<input name="prenom" id="prenom" type="text" class="form-poshytip" title="Entrez votre nom" />
<label>Prénom</label></div>
<div>
<input name="nom" id="nom" type="text" class="form-poshytip" title="Entrez votre nom" />
<label>Nom</label></div>
<div>

<select name="jour" id="jour" class="form-poshytip">
<option selected="selected">Jour</option> <option>01</option><option>02</option>
<option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>
</select>
<select name="mois" id="mois"class="form-poshytip">
<option selected="selected">Mois</option><option>Janvier</option><option>Février</option><option>Mars</option><option>Avril</option><option>Mai</option><option>Juin</option><option>Juillet</option><option>Août</option><option>Septembre</option><option>Octobre</option><option>Novembre</option> <option>Décembre</option>
</select>
<select name="annee" id="annee" class="form-poshytip">
<option selected="selected">Année</option><option>2006</option><option>2007</option> <option>2008</option>
</select> <label>Date de naissance</label>
</div>
<div>
<input name="email" id="email" type="text" class="form-poshytip" title="Entrez votre courriel" />
<label>Courriel</label>
</div>
<div>
<input type="hidden" value="kagamushu@hotmail.com" name="to" id="to" />
<input type="hidden" value="Courriel" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
</div>

<p><input type="button" value="Envoyez" name="submit" id="submit" /> <span id="error" class="warning"Message</span></p>
</fieldset></form>

thanks for your help!
dirtmcgirt
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Oct 23, 2012 11:55 am

Re: contact form not returning all info

Postby seandisanti » Wed Oct 24, 2012 7:58 am

you're overwriting it in the quoted section on my first reply. here's how...
Code: Select all
    //data
    $msg = "PRÉNOM: " .$_POST['prenom'] ."<br>\n";
    $msg = "NOM: " .$_POST['nom'] ."<br>\n";// = assignment operator overwrites the value already stored
    $msg .= "JOUR: " .$_POST['jour'] ."<br>\n";// .= appends new data to old.
    $msg .= "MOIS: " .$_POST['mois'] ."<br>\n";// so the first line is overwritten as soon as the second is run
    $msg .= "ANNEE: " .$_POST['annee'] ."<br>\n";// and then all of these values are tacked onto it.
    $msg .= "COURRIEL: " .$_POST['email'] ."<br>\n";
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: contact form not returning all info

Postby dirtmcgirt » Wed Oct 24, 2012 10:35 am

Hey, so i ended up re-writing the data call like this:

$msg = $_POST['prenom']." ".$_POST['nom']." ".$_POST['email']." ".$_POST['tel']." ".$_POST['med'];

And it friggin works!
thanks a million:)))
dirtmcgirt
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Oct 23, 2012 11:55 am

Re: contact form not returning all info

Postby seandisanti » Thu Oct 25, 2012 8:39 am

good job, congrats. glad to help.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.