2013-06-06 35 views
-1

这是我尝试发送电子邮件的表单中的一部分。我希望能够看到用户检查哪些答案并通过电子邮件将表单提交给我自己。我不能使用复选框以外的任何内容,因为我正在向常量联系人列表添加信息。使用复选框的PHP电子邮件表格

<label for="agegroup">What age group are you in?</label><br/> 

<input type="checkbox" value="Teens" name="Lists[]" id="list_Teens" /> 
<label for="list_Teens"><img src="http://theswagsociety.com/wp-content/uploads/2013/06/teen.png" alt="teen age group" width="239" height="77" class="alignnone size-full wp-image-5892" /></label> 

<input type="checkbox" value="20\'s" name="Lists[]" id="list_20\'s" /> 
<label for="list_20\'s"><img src="http://theswagsociety.com/wp-content/uploads/2013/05/20.png" alt="20 somethings" width="255" height="79" class="alignnone size-full wp-image-5895" /></label> 

<input type="checkbox" value="30\'s" name="Lists[]" id="list_30\'s" /> 
<label for="list_30\'s"><img src="http://theswagsociety.com/wp-content/uploads/2013/05/30.png" alt="30 somethings" width="257" height="79" class="alignnone size-full wp-image-5897" /></label> 

<input type="checkbox" value="40\'s" name="Lists[]" id="list_40\'s" /> 
<label for="list_40\'s"><img src="http://theswagsociety.com/wp-content/uploads/2013/05/40.png" alt="40 somethings" width="257" height="79" class="alignnone size-full wp-image-5898" /></label> 

<input type="checkbox" value="50\'s" name="Lists[]" id="list_50\'s" /> 
<label for="list_50\'s"><img src="http://theswagsociety.com/wp-content/uploads/2013/05/50.png" alt="50 somethings" width="256" height="79" class="alignnone size-full wp-image-5900" /></label> 

回答

-2

Ans From Some Post on SO。
尝试其中j查询

$('input:checkbox:(:checked)').each(function() { 
     // your code here 
    }) 

实施例:

<input type="checkbox" value="Red">Red</input> 
<input type="checkbox" value="Green">Green</input> 
<input type="checkbox" value="Blue">Blue</input> 
<input type="button" value="Get checkboxes" id="getCheckboxesButton"></input> 
<div id="debugOutput"> 
</div> 

Ĵ查询

$(document).ready(function() { 
    $('#getCheckboxesButton').live('click', function(event) { 
     var checkboxValues = []; 
     $('input[type="checkbox"]:checked').each(function(index, elem) { 
      checkboxValues.push($(elem).val()); 
     }); 
     $('#debugOutput').html(checkboxValues.join(',')); 
    }); 
}); 

或用PHP

尝试
2

用户检查的唯一复选框将被提交,其他复选框值将不会在php中可用。

可以使用...

<?php 

    if(isset($_POST['submit_email'])){ 
     extract($_POST); // this will extract all posted data as variables 

     if(isset($list)){ // checks if any checkbox is checked 
       foreach($list as $item){  // loop all the checked checkedboxes 
        //here you can strore the value in string or the way you want to format 
       } 
     } 
    }