PHP电子邮件表单使用复选框

时间:2013-06-06 06:03:17

标签: php

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

<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 个答案:

答案 0 :(得分: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
              }
         }
     }

答案 1 :(得分:-2)

来自SO的一些帖子。 尝试使用j Query

 $('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>

j查询

$(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>