dimis283
(Dimis283)
September 20, 2009, 10:27pm
1
I want to create a new user abd user password repeat but the model can not read the password_repeat
Since the password_repeat is at $_post, model can not read id
Array ( [users] => Array ( [usr_name] => dimis [usr_type] => 1 [usr_pass] => dimis [password_repeat] => dimis [user_surname] => dimis [usr_email] => dimis@yahoo.gr [usr_phone] => [usr_descr] => ) [yt0] => Create )
Array ( [usr_name] => dimis [usr_type] => 1 [usr_pass] => dimis [user_surname] => dimis [usr_email] => dimis@yahoo.gr [usr_phone] => [usr_descr] => [usr_id] => [cmp_id] => )
so I do
model
public $password_repeat;
...
array('password_repeat', 'required', 'on'=>'newuser'),
array('usr_pass','compare', 'compareAttribute'=>'password_repeat', 'on'=>'newuser'),
..........
controller
...
$model=new users;
$type=$model->getTypeOptions();
$model->scenario='newuser';
// $model->setScenario('create');
if(isset($_POST['users']))
{//echo $model->scenario;var_dump($_POST);die();
$model->attributes=$_POST['users'];
print_r($_POST);
print_r( $model->attributes);...
form
<?php if ($update==false) { ?>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'usr_pass'); ?>
<?php echo CHtml::activePasswordField($model,'usr_pass'); ?>
</div>
<div class="simple"> <?php // echo $model->password_repeat; ?>
<?php echo CHtml::activeLabelEx($model,'password_repeat'); ?>
<?php echo CHtml::activePasswordField($model,'password_repeat',array('size'=>50,'maxlength'=>50)); ?>
</div>
<?php }?>
dimis283
(Dimis283)
September 20, 2009, 10:41pm
2
I put also
... public function rules()
{
return array(
array('usr_pass','length','max'=>64, 'min'=>6),
array('password_repeat','length','max'=>64, 'min'=>6),...
public function safeAttributes()
{
return array(
'usr_name, usr_pass,usr_type, password_repeat,user_surname,usr_email,usr_phone,usr_descr',
Badger
(Stephen Lowry)
September 21, 2009, 10:51am
3
I can’t see what is wrong.
I quickly checked my files for my current project and the only stuff I have different are:
I don’t have "$type=$model->getTypeOptions();
$model->scenario='newuser';"
You’re calling model->save() after $model->attributes=$_POST[‘users’];, right?
dimis283
(Dimis283)
September 21, 2009, 10:59am
4
I had to set the scenario (newuser) at safeAttributes.\As i test it, it is ok
donyaee
(Donyaee)
September 22, 2009, 6:26am
5
I have the same issue with the following code. The password_repeat field is posted but cannot be placed into the model attributes thru the
$model->attributes = $_POST[‘User’]; code line. FYI the action name is actionCreate. By saying scenario, do you mean action name? Am I doing anything wrong here?
class User extends CActiveRecord
{
public $password_repeat;
...
public function safeAttributes()
{
return array(
'create'=>'username, password, password_repeat',
);
}
}
dimis283
(Dimis283)
September 22, 2009, 7:00am
6
I used
public function rules() {
return array(
array('usr_pass','length','max'=>64, 'min'=>6),
array('password_repeat','length','max'=>64, 'min'=>6), array('password_repeat', 'required', 'on'=>'newuser'),
array('usr_pass','compare', 'compareAttribute'=>'password_repeat', 'on'=>'newuser'),
....
public function safeAttributes() {
return array(
parent::safeAttributes(),
'newuser' => 'usr_download,usr_name, usr_pass, password_repeat,usr_type,user_surname,usr_email,usr_phone,usr_descr',
);
}
....
donyaee
(Donyaee)
September 22, 2009, 7:51pm
7
dimis283:
I used
public function rules() {
return array(
array('usr_pass','length','max'=>64, 'min'=>6),
array('password_repeat','length','max'=>64, 'min'=>6), array('password_repeat', 'required', 'on'=>'newuser'),
array('usr_pass','compare', 'compareAttribute'=>'password_repeat', 'on'=>'newuser'),
....
public function safeAttributes() {
return array(
parent::safeAttributes(),
'newuser' => 'usr_download,usr_name, usr_pass, password_repeat,usr_type,user_surname,usr_email,usr_phone,usr_descr',
);
}
....
I am doing same thing in my code but no password_repeat at all. I realized that the overriding the safeAttributes () has no effect on the $model->attributes. When I do print_r($model->attributes) the output is same with and without overriding the safeAttributes (). Any thoughts on this?
Thanks,
Ramin