
November 2nd, 2012, 08:09 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 2 h 6 m
Reputation Power: 0
|
|
|
PHP-General - Php form not receiving checkbox data
hello,
i am working on a form. All information is received correctly except for the the data from checkboxes.
I've seen lots of examples online, but i can't get mine to work! I believe the problem is in the javascript but i just can't figure it out. Thanks for your help.
Here is a bit of my HTML:
<form id="contactForm" name="listForm" action="#" method="post">
<fieldset>
<input type="checkbox" id="A12 SS MER 19H30 CAS" name="choice2" value="260" onchange="checkTotal()"class="form-poshytip" title="Cochez ici" />
<label>Mercredi 19h30 à 22h, niveaux 1,2,3</label>
<br/>
<input type="checkbox" id="A12 SS MER 19H30 CAS" name="choice" value="260" onchange="checkTotal()"class="form-poshytip" title="Cochez ici" />
<label>Mercredi 19h30 à 22h, niveaux 1,2,3</label> <br/>
<input name="nom" id="nom" type="text" class="form-poshytip" title="Entrez votre nom" />
<label>Nom</label>
Java:
$(document).ready(function(){
// on submit...
$("#contactForm #submit").click(function() {
$("#error").hide();
var nom = $("input#nom").val();
var choice = $("input#choice").val();
var choice2 = $("input#choice2").val();
var sendMailUrl = $("#sendMailUrl").val();
//to, from & subject
var to = $("#to").val();
var from = $("#from").val();
var subject = $("#subject").val();
// data string
var dataString = 'nom='+ nom
+ '&choice2=' + choice2
+ '&choice=' + choice
+ '&to=' + to
+ '&from=' + from
+ '&subject=' + subject;
// ajax
$.ajax({
type:"POST",
url: sendMailUrl,
data: dataString,
});
});
PHP:
<?php
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['email'];
$msg = "NOM: ".$_POST['prenom']."<br> "
.$_POST['choice2]." <br>"
.$_POST['choice'];
$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";?>:
|