我在CakePHP中创建了一个登录页面,需要添加一个注册按钮,这是\ View \ Users \ login.ctp的代码:
<div class="container">
<div class="login-content">
<?php echo $this->Html->image('logo1.png', array('alt' => 'fivassist Logo')); ?>
<?php echo $this->Form->create('User'); ?>
<div class="login-form">
<h2>Bem-vindo!</h2>
<ul>
<li>
<label>E-mail:</label>
<?php echo $this->Form->input('email',
array('label' => false, 'autocomplete' => 'off')); ?>
</li>
<li><label>Password:</label>
<?php echo $this->Form->input('password',
array('label' => false, 'autocomplete' => 'off')); ?>
</li>
</ul>
</div> <!-- end login-form -->
<?php echo $this->Session->flash(); ?>
<?php echo $this->Form->submit('Login', array('id' => 'login-bt')); ?>
<a href="#" id="forgot">Esqueceu-se da sua password?</a>
<?php echo $this->Form->button('Register'); ?>
</div> <!-- end login-content -->
</div> <!-- end container -->
我如何将注册按钮重定向到/user/add.ctp?
你能帮帮我吗? 谢谢。答案 0 :(得分:1)
您需要将表单指向&#34;注册&#34;行动:我建议将此行动与您的&#34;新用户&#34;行动 - 有时你想要有不同的逻辑。
这应该提交给/users/register
。请注意$this->Form->create
上的参数:
echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'register')));
echo $this->Form->input('email', array('class' => 'form-control', 'label' => false,'placeholder' => 'Email'));
echo $this->Form->input('pwd', array('class' => 'form-control', 'label' => false, 'placeholder' => 'Password'));
echo $this->Form->input('pwd_repeat', array('class' => 'form-control', 'label' => false, 'placeholder' => 'Password'));
echo $this->Form->submit('Register', array('class' => 'btn btn-large btn-primary'));
echo $this->Form->end();
我还建议您阅读docs for HtmlHelper,他们可以提供很多帮助。
答案 1 :(得分:0)
您想要点击按钮登录时会提交操作登录并点击按钮注册它是否提交给操作用户/添加?
如果是这样你可以使用javascript或jQuery
$(function () {
// when click button login
$('#btn-login').on('click', function () {
// #form: id of form, you should named it
$('#form').atrr('action', 'login');
});
// when click button register
$('#btn-register').on('click', function () {
$('#form').atrr('action', 'register');
});
$('#form').submit();
});
如果你想点击按钮注册,它会重定向到查看add.ctp
这样你就可以使用HtmlHelper
echo $this->Html->link('Register', array('action' => 'add'), array('class' => 'btn-register', 'id' => 'btn-register', 'escape' => false));
然后为btn-register
定义css.btn-register {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
color: #333;
background-color: #fff;
border-color: #ccc;
}