Cakephp - 复选框名称

发布于 2025-01-06 06:21:01 字数 1051 浏览 0 评论 0原文

目前,我已经成功创建了复选框。 我设置的数组如下:

$emailName = $this->User->find('list', array(
    'fields' => array('User.username', 'User.email')
    ));

输出如下:

array
  'admin' => string '[email protected]' (length=11)
  'test' => string '[email protected]' (length=14)
  'Floo' => string '[email protected]' (length=16)

我试图使复选框显示用户名而不是 view.ctp 中的用户电子邮件。

我尝试在 view.ctp 中使用以下代码

<?php echo $this->Form->input('Address_list.['.$emailName['username'].']', array(
    'type' => 'select',
    'multiple' => 'checkbox',
    'options' => $emailName['email']
    )); ?>

但是,这似乎不起作用。有什么想法吗?

Currently, i have succeeded in creating the checkbox.
The array which i have setup is as below:

$emailName = $this->User->find('list', array(
    'fields' => array('User.username', 'User.email')
    ));

The output is as follows:

array
  'admin' => string '[email protected]' (length=11)
  'test' => string '[email protected]' (length=14)
  'Floo' => string '[email protected]' (length=16)

I'm trying to make the checkbox shows the username instead of the user email in view.ctp.

I have tried using the following code in view.ctp

<?php echo $this->Form->input('Address_list.['.$emailName['username'].']', array(
    'type' => 'select',
    'multiple' => 'checkbox',
    'options' => $emailName['email']
    )); ?>

However, it seems that this doesn't work. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2025-01-13 06:21:01

您没有正确格式化复选框列表的表单字段。尝试将其更改为:

echo $this->Form->input('Address_list', array(
    'multiple' => 'checkbox',
    'options' => $emailName, 
));

但是,这将根据用户选择的电子邮件返回用户名的值。它创建这样的表单:

<label for="Address_list">Address List</label>
<input type="hidden" id="Address_list" value="" name="data[Address_list]"/>
<div class="checkbox"><input type="checkbox" id="AddressListAdmin" value="admin" 
   name="data[Address_list][]"/><label for="AddressListAdmin">[email protected]</label></div>
<div class="checkbox"><input type="checkbox" id="AddressListTest" value="test"
   name="data[Address_list][]"/><label for="AddressListTest">[email protected]</label></div>
<div class="checkbox"><input type="checkbox" id="AddressListFloo" value="Floo" 
   name="data[Address_list][]"/><label for="AddressListFloo">[email protected]</label></div>

You are not formatting your form field for the checkbox list correctly. Try changing it to this:

echo $this->Form->input('Address_list', array(
    'multiple' => 'checkbox',
    'options' => $emailName, 
));

However, this will return the value of Username based on the selection of Email the user chooses. It creates the form like this:

<label for="Address_list">Address List</label>
<input type="hidden" id="Address_list" value="" name="data[Address_list]"/>
<div class="checkbox"><input type="checkbox" id="AddressListAdmin" value="admin" 
   name="data[Address_list][]"/><label for="AddressListAdmin">[email protected]</label></div>
<div class="checkbox"><input type="checkbox" id="AddressListTest" value="test"
   name="data[Address_list][]"/><label for="AddressListTest">[email protected]</label></div>
<div class="checkbox"><input type="checkbox" id="AddressListFloo" value="Floo" 
   name="data[Address_list][]"/><label for="AddressListFloo">[email protected]</label></div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文