如何使用简单的PHP发布表单复选框数据?

时间:2015-03-04 17:03:38

标签: php forms checkbox

您好我是PHP的新手,并决定尝试为我正在创建的网站创建一个表单。除了发送复选框数据之外,我设法转到我的邮件地址 - 如果选中了多个复选框,则只会在发布的电子邮件中显示选中的最后一个复选框。任何人都可以告诉我怎么做到这一点? 以下是www.newsite0914.i4dsign.co.uk/contact.php中的表格代码:

<form id="contact_form2" name="contact_formB" method="post" action="post.php">
        .....
                    <table border="0" cellpadding="0" cellspacing="0" width="100%" id="nestedTable2">
                    <tr>
                    <td colspan="2">
                    Services interested in&quest;
                    </td>
                    </tr>
                    <tr>
                    <td valign="top">
                    Website <input type="checkbox" name="service[]" value="web" />
                    </td>
                    <td align="right">
                    Logo <input type="checkbox" name="service[]" value="logo" style=" margin-right: 50px;" />
                    </td>
                    </tr>
                    <tr>
                    <td>
                    Stationery <input type="checkbox" name="service[]" value="stationery" />
                    </td>
                    <td valign="top" align="right" >
                    Advert <input type="checkbox" name="service[]" value="advert"style=" margin-right: 50px;" />
                    </td>
                    </tr>
                    <tr>
                    <td valign="top" colspan="2">
                    Other <input type="checkbox" name="service[]" value="other" /> <textarea cols="25" rows="1" name="other" value="other"style="margin-left: 10px;"></textarea>
                    </td>
                    </tr>
                    </table>
                ...
            <tr>
                <td colspan="2">
                Security Task: 6 + 7 =
                <input name="security" size="2" />

                <input type="submit" value="Send your details" onClick="checkDetailsB()" style="margin-left: 20px;"  /> 

                <!--<input type="reset" value="Reset"  />-->
                </td>
            </tr>
        </table>
        </form>

这是帖子php脚本(www.newsite0914.i4dsign.co.uk/post.php):

$to = "julian@i4dsign.co.uk";
$subject = "New Contact Form Submission";
$message = "....\n\nService: $service[$i]\n\n....";

if ($security=="13"){
    mail($to,$subject,$message);    
    header("Location:contact.php?s=1");
}
else{
    header("Location:contact.php?s=2");
}

提前谢谢你。我希望有人可以提供帮助。

1 个答案:

答案 0 :(得分:0)

$to = "julian@i4dsign.co.uk";
$subject = "New Contact Form Submission";
$message = "\n\nService: " . implode(', ', $_POST['service']);