-1

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

<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>
4

2 回答 2

2

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

您可以使用...

<?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
              }
         }
     }
于 2013-06-06T06:12:41.607 回答
-2

来自一些关于 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

 <?php

    echo (is_array($_REQUEST['serviceType']) ? implode("\n", $_REQUEST['serviceType']) : $_REQUEST['serviceType']);

    ?>


   <form action="" method="post">
        Graphic Design&nbsp;<input name="serviceType[]" id="design" type="checkbox" value="Graphic Design" />&nbsp;&nbsp;&nbsp;&nbsp;
        Web Development&nbsp;<input name="serviceType[]" id="webdev" type="checkbox" value="Web Development" />&nbsp;&nbsp;&nbsp;&nbsp;
        Application Development&nbsp;<input name="serviceType[]" id="appdev" type="checkbox" value="App Development" />&nbsp;&nbsp;&nbsp;&nbsp;
        Embroidery&nbsp;<input name="serviceType[]" id="embroidery" type="checkbox" value="Embroidery" />&nbsp;&nbsp;&nbsp;&nbsp;
        Engraving&nbsp;<input name="serviceType[]" id="engrave" type="checkbox" value="Engraving" /><br/><br/>
        <input type="submit" />
    </form>
于 2013-06-06T06:12:20.043 回答