【发布时间】:2013-04-10 22:34:46
【问题描述】:
过去 4 小时我一直在研究这个问题,一个又一个问题。现在我终于解决了我的大部分问题,我似乎无法解决最后的问题。
问题:我必须向学生发送一封电子邮件(电子邮件存储在 DB 中)。在电子邮件中必须有一个带有列表项的无序列表。那部分是简单的部分(html 电子邮件)。我现在面临的问题是我想获取表单的实际名称,而不是值,因为值只是
值="1" 值="2"
这不会为学生提供有关表格是什么的太多信息。
这些是我的输入字段:
<label id="form"><input type="checkbox" name="form[]" value="3" >DECSP</label>
<label id="form"><input type="checkbox" name="form[]" value="4" >DESNAP</label>
如果您再次注意到该值只是一个数字,我想实际获取 DESCP 和 DESNAP 表单的名称
这是我尝试过的:
$body .= '<ul>';
$forms = $this->input->post('form'); // The check boxes
$dbforms = $this->queue_model->first10() + $this->queue_model->elev9() + $this->queue_model->twenty_5() + $this->queue_model->twen8thir7() + $this->queue_model->checklists(); // Here I take the forms from the database and combine the arrays
$givenforms = array_intersect_assoc($dbforms, $forms); // Here I do an intersect where form_id matches the value
foreach ( $givenforms as $key => $value) { // If a match is good then give me the form_name
$body .= '<li>' . $value . '</li>';
}
$body .= '</ul>';
我很困惑从这里去哪里。希望大家理解。
我唯一能想到的就是做一个
foreach
遍历在复选框中选中的所有表单,然后在查询中
select * forms where form_id = (检查了什么表单)
然后
返回
表单的实际名称。
但是,我不知道这是否是一个合适的解决方案。提前感谢你们提供的任何信息。
编辑 1:
复选框必须是一个数组,以便我可以将学生收到的表格存储在数据库中。看看我的other question.
【问题讨论】:
-
不确定是否还有其他原因希望您的复选框选择以数组形式返回,但如果您使用
<input name="DECSP" type="checkbox">之类的东西,您将在 POST 数据中返回实际名称。跨度> -
对对...就像我当时想的那样 :( 好吧,看来我必须运行查询才能根据用户检查的内容从数据库中获取 form_name。我会来的完成该部分后返回并更新我的帖子/给出答案。
-
<label>s 不属于已发布的表单数据。
标签: php arrays codeigniter html-email array-intersect