【问题标题】:PHP - How to Add a Tag for Each Selected Checkbox in a FormPHP - 如何为表单中的每个选定复选框添加标签
【发布时间】:2018-09-07 03:19:26
【问题描述】:

有谁知道如何使用纯 PHP为每个选中的复选框添加标签?我的表单与Active Campaign API集成。(您不必熟悉API)

一切都很好,但是键(标签)返回一个字符串,其中包含所有值(兴趣),并由列分隔。

  $interests_val = $_POST['interests_val'];

  $contact = array(
    "email"                           => $user_info->user_email,
    "tags[0]"                         => "[Interest] ".implode(", ", $interests_val),

  );

相反,我想为每个选定的值或复选框添加一个标签。有没有办法更有效地执行此操作?我有超过 20 个复选框。

 $interests_val = $_POST['interests_val'];

  $contact = array(
    "email"                           => $user_info->user_email,
    "tags[0]"                         => "[Interest] ".$interests_val[0]),
    "tags[1]"                         => "[Interest] ".$interests_val[1]),
    "tags[2]"                         => "[Interest] ".$interests_val[2]),

  );

谢谢!

【问题讨论】:

    标签: php forms api customization


    【解决方案1】:

    尝试在$interests_val 上使用循环,并在使用固定值(在本例中为email)创建$contact 数组后,动态创建其他键:

    $interests_val=implode($_POST['interests_val']);
    
    $contact = array("email"=> $user_info->user_email);
    foreach($interests_val as $key=>$value){
       $contact["tags{$key}"] = "[Interest] {$value}";
    }
    

    【讨论】:

    • 谢谢,但它似乎不起作用。它不返回标签。有没有其他方法可以解决这个问题?
    猜你喜欢
    • 2012-01-21
    • 2021-04-29
    • 2017-08-29
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2020-07-15
    相关资源
    最近更新 更多