【问题标题】:is active field name breaking this form是活动字段名称打破了这种形式
【发布时间】:2018-03-29 13:59:50
【问题描述】:

自从我在此表单中添加了活动复选框后,我的行为一直很奇怪,提交按钮只能在文本之外单击,并且在提交表单时活动字段的选中状态未注册,它总是显示为真。我检查了 active 是否是保留字,因为这种行为非常时髦,但无济于事。我是菜鸟吗?

<div class="add-form">
    <?= $this->Form->create($member) ?>
        <legend><?= __('Edit Member') ?></legend>
        <?php
            echo $this->Form->control('membership_no');
            echo $this->Form->control('password');
            echo $this->Form->control('email');
            echo $this->Form->control('company_id', ['options' => $companies]);
            echo $this->Form->control('terms_agreed');
            echo $this->Form->control('change_password');
            echo $this->Form->control('active');
        ?>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>
</div>

如果这里有任何导入是我添加活动列的迁移

    <?php
use Migrations\AbstractMigration;

class AddActiveToMembers extends AbstractMigration
{
    public function change()
    {
        $table = $this->table('members');
        $table->addColumn('active', 'boolean', [
            'default' => true,
            'null' => false,
        ]);
        $table->update();
    }
}

【问题讨论】:

    标签: php forms cakephp cakephp-3.0


    【解决方案1】:

    尝试使用其他字段名称一次。

    'default'=>true 可能返回值 '1' ...删除并检查输出。

    那是

      <?php
      use Migrations\AbstractMigration;
    
      class AddActiveToMembers extends AbstractMigration
       {
        public function change()
          {
          $table = $this->table('members');
          $table->addColumn('active_col', 'boolean', [
            'default' => true,
            'null' => false,
         ]);
          $table->update();
       }
     }
    


       <?php
       use Migrations\AbstractMigration;
    
       class AddActiveToMembers extends AbstractMigration
       {
        public function change()
         {
          $table = $this->table('members');
          $table->addColumn('active', 'boolean', [            
            'null' => false,
          ]);
          $table->update();
         }
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2016-11-16
      • 1970-01-01
      相关资源
      最近更新 更多