douren1891 2013-12-17 22:09
浏览 63
已采纳

多个PHP电子邮件功能。 (复选框)

What should I type in PHP instead of I got now to receive in mail all of the answers typed in checkboxes by user. Now I have only one. Thanks

PHP:

$email_message .= "Sport: ".clean_string($_POST["sport"])."
";
$email_message .= "Music: ".clean_string($_POST["music"])."
";

HTML:

<div id="Oobj58" class="Oobj">
    <input type="checkbox" name="sport" value="Kosz" />koszykówka<br>
    <input type="checkbox" name="sport" value="Zimowe" />sporty zimowe<br>
    <input type="checkbox" name="sport" value="Konie" />jeździectwo konne<br>

</div>

    <div id="Oobj61" class="Oobj">

    <input type="checkbox" name="rozrywka" value="festiwal" />festiwale<br />
    <input type="checkbox" name="rozrywka" value="wesole" />wesołe miasteczka<br />
    <input type="checkbox" name="rozrywka" value="zespolowo"/>paintball,bilard,kręgle..<br/>
    </div>

Edit: Thanks but not exactly can type different 'names' cause I also have one checkboxe to set all on check at once and it works with JS like this:

   <div id="Oobj61" class="Oobj">

<script language="JavaScript">
function toggle2(source) {
  checkboxes = document.getElementsByName('rozrywka');
  for(var i=0, n=checkboxes.length;i<n;i++) {
    checkboxes[i].checked = source.checked;
  }
}
</script>

<input type="checkbox" onClick="toggle2(this)" /><br>

<input type="checkbox" name="rozrywka" value="club" />kluby<br />
<input type="checkbox" name="rozrywka" value="puby" />puby<br />
<input type="checkbox" name="rozrywka" value="koncert" />koncerty<br />
<input type="checkbox" name="rozrywka" value="festiwal" />festiwale<br />
<input type="checkbox" name="rozrywka" value="wesole" />wesołe miasteczka<br />
<input type="checkbox" name="rozrywka" value="zespolowo" />paintball,bilard,kręgle...<br 

/>
</div>
  • 写回答

1条回答 默认 最新

  • doutang3077 2013-12-17 22:14
    关注

    I'm not 100% sure what it is you're asking here, but if you'd like to see if a checkbox is set you can do the following:

    if(isset($_POST['checkbox-name-here'])){
       //it's set code here, maybe set a variable...
       $var = "checkbox value";}
    

    That's a rough example, but you should get the drift.

    If you're trying to get multiples - then give each checkbox a unique name:

    <div id="Oobj58" class="Oobj">
        <input type="checkbox" name="sport1" value="Kosz" />koszykówka<br>
        <input type="checkbox" name="sport2" value="Zimowe" />sporty zimowe<br>
        <input type="checkbox" name="sport3" value="Konie" />jeździectwo konne<br>
    </div>
    

    Then in PHP you can check if each value is set:

    if(isset($_POST['sport1'])){$sport1="sport1";}
    if(isset($_POST['sport2'])){$sport2="sport2";}
    if(isset($_POST['sport3'])){$sport3="sport3";}
    
    $email_message .= "Sports: ".clean_string($_POST["sport1"])."
    "
                                .clean_string($_POST["sport2"])."
    "
                                .clean_string($_POST["sport3"])."
    ";
    

    There are much tidier ways of doing it, but that should help you work it out?

    Alternatively you could give each of the checkboxes the same name, and then construct an array out of them. This array can then be looped in the PHP email handler. Look at this SO answer for a great example: https://stackoverflow.com/a/4516887/3112128

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置