作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
只是想制作一个非常标准的用户编辑页面。 “密码”和“重新密码”开始隐藏,但可以通过单击“编辑密码”按钮“打开”。
但是 - 我不断收到来自安全组件的“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/
只是想制作一个非常标准的用户编辑页面。 “密码”和“重新密码”开始隐藏,但可以通过单击“编辑密码”按钮“打开”。 但是 - 我不断收到来自安全组件的“auth”黑洞错误。 根据 the CakePHP
我是一名优秀的程序员,十分优秀!