gpt4 book ai didi

javascript - UnlockField 在 CakePHP 中不起作用

转载 作者:行者123 更新时间:2023-12-05 07:59:00 25 4
gpt4 key购买 nike

只是想制作一个非常标准的用户编辑页面。 “密码”和“重新密码”开始隐藏,但可以通过单击“编辑密码”按钮“打开”。

但是 - 我不断收到来自安全组件的“auth”黑洞错误。

根据 the CakePHP book ,我尝试在 View 中用这个解锁字段(尝试在字段之前,字段之后,就在表单内部,就在表单之前,以及在表单的末尾:

$this->Form->unlockField('User.password');
$this->Form->unlockField('User.re-password');

但是 - 没有帮助。我能让它工作的唯一方法是完全解锁整个 Action (看起来不太理想):

$this->Security->unlockedActions = array('admin_edit');

如果我不禁用这些字段,那么它会起作用,但我需要禁用它们,因为如果我不这样做,内置的“notEmpty”方面会在查找这些字段时导致 javascript 错误。

查看/HTML:

<div id="edit-password-area" style="display:none;">
<div class="form-group">
<label>Password</label>
<?php echo $this->Form->input('User.password', array('class'=>'input-xxlarge form-control', 'value'=>'', 'disabled'=>'disabled')); ?>
<p class="note">Must be at least 8 characters in length.</p>
</div>
<div class="form-group">
<label>Verify Password</label>
<?php echo $this->Form->input('User.re_password', array('type'=>'password', 'class'=>'input-xxlarge form-control', 'value'=>'', 'disabled'=>'disabled')); ?>
<p class="note">Must exactly match the "Password".</p>
</div>
</div>

<div id="edit-password-button-area">
<a href="javascript:showPasswordArea();">Edit Password</a>
</div>

<div id="dont-edit-password-button-area" style="display:none;">
<a href="javascript:hidePasswordArea();">Don't Edit Password</a>
</div>

Javascript:

<script>
function showPasswordArea() {
$('#edit-password-area').show();
$('#edit-password-area input').removeAttr('disabled');
$('#dont-edit-password-button-area').show();
$('#edit-password-button-area').hide();
$('#UserPassword').focus();
}
function hidePasswordArea() {
$('#edit-password-area').hide();
$('#edit-password-area input').prop('disabled', 'disabled');
$('#dont-edit-password-button-area').hide();
$('#edit-password-button-area').show();
}
</script>

最佳答案

试试这个语法:

$this->Security->unlockedFields = array('yourfield');

关于javascript - UnlockField 在 CakePHP 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23347122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com