我正在尝试在提交上验证表单,但它无效并且表单提交没有错误。视图中不显示任何消息。 我在用户模型
中使用了下面提到的代码public $validate = array(
'fname' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
),
'between' => array(
'rule' => array('between', 3, 15),
'message' => 'Between 5 to 15 characters'
),
),
'email' => array('email' => array(
'rule' => 'email',
'message' => 'Email must be a valid email address!'
),
'unique' => array(
'rule' => 'isUnique',
'message' => 'User already registered!'
)
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
),
'between' => array(
'rule' => array('between', 8, 15),
'message' => 'Between 8 to 15 characters'
),
'slug' => array(
'rule' => '/^[a-z0-9A-Z@#_]{8,}$/i',
'message' => 'Only letters, integers ,@, # and Underscore(_), min 8 characters'
),
),
);
UsersController.php
class UsersController extends AppController {
public $name = 'Users';
public function register(){
if(($this->request->is('post'))||($this->request->is('post'))){
$this->User->create();
$this->User->save($this->request);
}
}
register.ctp
<div class="col-lg-12">
<div class="row">
<h2 class="col-lg-12 heading">Register</h2>
<?php
echo $this->Form->create('User', array('type'=>'file'));
echo '<div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">First Name</label>');
echo $this->Form->input('fname', array('type'=>'text', 'div'=>array('class'=>'col-sm-5'), 'label'=>false, 'class'=>'form-control', 'placeholder'=>'First Name'));
echo '</div><div class="clearfix"></div><div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">Middle Name : </label>');
echo $this->Form->input('mname', array('type'=>'text', 'div'=>array('class'=>'col-sm-5'), 'label'=>false, 'class'=>'form-control', 'placeholder'=>'Middle Name'));
echo '</div><div class="clearfix"></div><div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">Last Name : </label>');
echo $this->Form->input('lname', array('type'=>'text', 'div'=>array('class'=>'col-sm-5'), 'label'=>false, 'class'=>'form-control', 'placeholder'=>'Last Name'));
echo '</div><div class="clearfix"></div><div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">Date Of Birth : </label>');
echo $this->Form->input('dob', array('type'=>'text', 'div'=>array('class'=>'col-sm-5'), 'label'=>false, 'class'=>'form-control', 'placeholder'=>'Date of Birht'));
echo '</div><div class="clearfix"></div><div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">Gender : </label>');
echo $this->Form->input('gender', array('options'=>array('0' => ' Male', '1' => ' Female', '2' => ' Other'),'type'=>'radio', 'separator'=>' ', 'div'=>array('class'=>'col-lg-7'), 'label'=>false, 'class'=>'','legend' => false));
echo '</div><div class="clearfix"></div><div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">E-Mail : </label>');
echo $this->Form->input('email', array('type'=>'text', 'div'=>array('class'=>'col-sm-5'), 'label'=>false, 'class'=>'form-control', 'placeholder'=>'E-Mail'));
echo '</div><div class="clearfix"></div><div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">Password : </label>');
echo $this->Form->input('password', array('type'=>'password', 'div'=>array('class'=>'col-sm-5'), 'label'=>false, 'class'=>'form-control', 'placeholder'=>'Password'));
echo '</div><div class="clearfix"></div><div class="form-group">';
echo $this->Html->div('col-sm-2', '<label for="inputTextl1" class="control-label">Confirm Password : </label>');
echo $this->Form->input('cpassword', array('type'=>'password', 'div'=>array('class'=>'col-sm-5'), 'label'=>false, 'class'=>'form-control', 'placeholder'=>'Confirm Password'));
echo '</div><div class="clearfix"></div><div class="col-sm-12" align="center">';
echo $this->Form->submit('Register', array('div'=>false, 'label'=>false, 'class'=>'btn btn-primary'));
echo '</div>';
?>
</div>
</div>