duanjizi9443 2013-08-07 00:26
浏览 72
已采纳

使用PHP post方法提交一组复选框值

Im trying to email a list of checkbox values using wp_mail the result of my code IS sending the email

but the value returns as an array.. I understand why, but I am not sure how to breakdown the array, I dont see how I can implement a foreach here.

PHP:

  //checkmarks post variable
       $checks = $_POST['personalization_result'];

  //php mailer variables
       $to = get_option('admin_email');
       $subject = "Someone sent a message from ".get_bloginfo('name');
       $headers = 'From: '. $email . "rn" .

         $sent = wp_mail($to, $subject, $checks, $headers);

HTML:

<form action="<?php the_permalink(); ?>" method="post">
<input type="hidden" name="submitted" value="1">

    <input type="submit">

<li class="option table selected">
    <div class="option-checkbox">
        <input type="hidden" value="0" name="personalization_result[memory_0]">
        <input type="checkbox" value="1" name="personalization_result[memory_0]" id="personalization_result_memory_0" checked="checked">
    </div>
    </div>
</li>

<li class="option table selected">
    <div class="option-checkbox">
        <input type="hidden" value="0" name="personalization_result[memory_1]">
        <input type="checkbox" value="1" name="personalization_result[memory_1]" id="personalization_result_memory_1" checked="checked">
    </div>
    </div>
</li>

</form>
  • 写回答

1条回答 默认 最新

  • duanou2016 2013-08-07 00:30
    关注

    Before you call the wp_mail function, you need to process your $checks variable and turn it into a string, e.g.:

       $checks = $_POST['personalization_result'];
       $checkString = ''
       foreach ($checks as $k=>$v) {
           //some code to build up $checkString
       }
    

    You'd then obviously have to use $checkString instead of $checks in your wp_mail call . . .

    Alternatively, if you don't care about the keys, you could do something like:

         $sent = wp_mail($to, $subject, implode("|",$checks), $headers);
    

    Then you'd end up with something like "0|1"

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

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动