PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 2nd, 2012, 08:09 AM
billybeaver billybeaver is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 billybeaver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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";?>:

Reply With Quote
  #2  
Old November 2nd, 2012, 09:28 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 1 Day 1 h 42 m 30 sec
Reputation Power: 581
Welcome to the forum. There are a few problems with your question that make it difficult to understand what you are asking. First you need to enclose your PHP code in [ PHP ] tags and other code in [ CODE ] tags. See ManiacDan's New User Guide to learn how to post a question that will result in useful help along with many good debugging tips. Second, a minor point, Java != Javascript. Third and more directly related to what you are asking, I see no reference to your checkboxes in the PHP code so it is not clear if this is a javascript question or a PHP question.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old November 2nd, 2012, 05:35 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 48 m 54 sec
Reputation Power: 7053
In jQuery, calling .val() on a checkbox doesn't take into account whether or not the checkbox is checked.

To do that, you need to use something like this:
Code:
$('#id').is(':checked');


Which will evaluate to true or false depending on whether the checkbox is checked. If it is checked, you can then retrieve and include its value if you wish.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Php form not receiving checkbox data

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap