Closed ghost closed 9 years ago
What's the error? What data you're entering?
Is not that the syntax to make username
AND email
unique together?
https://github.com/yiisoft/yii2/blob/master/framework/validators/UniqueValidator.php#L27
@lucianobaraglia this doesn't work!! same problem.
sorry for my english
What's in your logs?
2014-11-13 17:21:58 [127.0.0.1][-][-][info][application] $_POST = [ '_csrf' => 'dTNsTXRyNEgFfhZ/FTEBJEZXBTUeAHUKGFkDFwE8QixNViMsPTwALQ==' 'User' => [ 'username' => 'sitraka' 'email' => 'ratsimbasitraka@gmail.com' 'password' => '1234' ] ]
$_COOKIE = [ '_identity' => '854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s:49:\"[\"31\",\"5FrGIVMraKbUjcWvOsDERkMN7XGk5eyB\",2592000]\";' 'PHPSESSID' => '3ha4m1ob5kceeubrjufs98f3d3' '_csrf' => '91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes:32:\"pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e\";' ]
$_SERVER = [ 'HTTP_HOST' => 'localhost' 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0' 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8' 'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5' 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate' 'HTTP_REFERER' => 'http://localhost/basic/web/index.php/user/create' 'HTTP_COOKIE' => '_identity=854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s%3A49%3A%22%5B%2231%22%2C%225FrGIVMraKbUjcWvOsDERkMN7XGk5eyB%22%2C2592000%5D%22%3B; PHPSESSID=3ha4m1ob5kceeubrjufs98f3d3; _csrf=91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes%3A32%3A%22pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e%22%3B' 'HTTP_CONNECTION' => 'keep-alive' 'HTTP_CACHE_CONTROL' => 'max-age=0' 'CONTENT_TYPE' => 'application/x-www-form-urlencoded' 'CONTENT_LENGTH' => '163' 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' 'SERVER_SIGNATURE' => ' Apache/2.4.7 (Ubuntu) Server at localhost Port 80 ' 'SERVER_SOFTWARE' => 'Apache/2.4.7 (Ubuntu)' 'SERVER_NAME' => 'localhost' 'SERVER_ADDR' => '127.0.0.1' 'SERVER_PORT' => '80' 'REMOTE_ADDR' => '127.0.0.1' 'DOCUMENT_ROOT' => '/var/www' 'REQUEST_SCHEME' => 'http' 'CONTEXT_PREFIX' => '' 'CONTEXT_DOCUMENT_ROOT' => '/var/www' 'SERVER_ADMIN' => '[no address given]' 'SCRIPT_FILENAME' => '/var/www/basic/web/index.php' 'REMOTE_PORT' => '48051' 'GATEWAY_INTERFACE' => 'CGI/1.1' 'SERVER_PROTOCOL' => 'HTTP/1.1' 'REQUEST_METHOD' => 'POST' 'QUERY_STRING' => '' 'REQUEST_URI' => '/basic/web/index.php/user/create' 'SCRIPT_NAME' => '/basic/web/index.php' 'PATH_INFO' => '/user/create' 'PATH_TRANSLATED' => '/var/www/user/create' 'PHP_SELF' => '/basic/web/index.php/user/create' 'REQUEST_TIME_FLOAT' => 1415899318.449 'REQUEST_TIME' => 1415899318 ]
I meant logs, not request info.
2014-11-13 17:16:58 [127.0.0.1][-][-][error][yii\base\UnknownPropertyException] exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: app\models\User::username, email' in /var/www/basic/vendor/yiisoft/yii2/base/Component.php:143 Stack trace:
2014-11-13 17:16:57 [127.0.0.1][-][-][info][application] $_POST = [ '_csrf' => 'YjR1VlFtN3ESeQ9kMC4CHVFQHC47H3YzD14aDCQjQRVaUTo3GCMDFA==' 'User' => [ 'username' => 'sitraka' 'email' => 'ratsimbasitraka@gmail.com' 'password' => '1234' ] ]
$_COOKIE = [ '_identity' => '854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s:49:\"[\"31\",\"5FrGIVMraKbUjcWvOsDERkMN7XGk5eyB\",2592000]\";' 'PHPSESSID' => '3ha4m1ob5kceeubrjufs98f3d3' '_csrf' => '91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes:32:\"pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e\";' ]
$_SERVER = [ 'HTTP_HOST' => 'localhost' 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0' 'HTTPACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,/_;q=0.8' 'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5' 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate' 'HTTP_REFERER' => 'http://localhost/basic/web/index.php/user/create' 'HTTP_COOKIE' => '_identity=854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s%3A49%3A%22%5B%2231%22%2C%225FrGIVMraKbUjcWvOsDERkMN7XGk5eyB%22%2C2592000%5D%22%3B; PHPSESSID=3ha4m1ob5kceeubrjufs98f3d3; _csrf=91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes%3A32%3A%22pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e%22%3B' 'HTTP_CONNECTION' => 'keep-alive' 'HTTP_CACHE_CONTROL' => 'max-age=0' 'CONTENT_TYPE' => 'application/x-www-form-urlencoded' 'CONTENT_LENGTH' => '161' 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' 'SERVER_SIGNATURE' => '
Apache/2.4.7 (Ubuntu) Server at localhost Port 80 ' 'SERVER_SOFTWARE' => 'Apache/2.4.7 (Ubuntu)' 'SERVER_NAME' => 'localhost' 'SERVER_ADDR' => '127.0.0.1' 'SERVER_PORT' => '80' 'REMOTE_ADDR' => '127.0.0.1' 'DOCUMENT_ROOT' => '/var/www' 'REQUEST_SCHEME' => 'http' 'CONTEXT_PREFIX' => '' 'CONTEXT_DOCUMENT_ROOT' => '/var/www' 'SERVER_ADMIN' => '[no address given]' 'SCRIPT_FILENAME' => '/var/www/basic/web/index.php' 'REMOTE_PORT' => '47899' 'GATEWAY_INTERFACE' => 'CGI/1.1' 'SERVER_PROTOCOL' => 'HTTP/1.1' 'REQUEST_METHOD' => 'POST' 'QUERY_STRING' => '' 'REQUEST_URI' => '/basic/web/index.php/user/create' 'SCRIPT_NAME' => '/basic/web/index.php' 'PATH_INFO' => '/user/create' 'PATH_TRANSLATED' => '/var/www/user/create' 'PHP_SELF' => '/basic/web/index.php/user/create' 'REQUEST_TIME_FLOAT' => 1415899017.095 'REQUEST_TIME' => 1415899017 ] 2014-11-13 17:21:59 [127.0.0.1][-][-][error][yii\base\UnknownPropertyException] exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: app\models\User::a1' in /var/www/basic/vendor/yiisoft/yii2/base/Component.php:143 Stack trace:2014-11-13 17:21:58 [127.0.0.1][-][-][info][application] $_POST = [ '_csrf' => 'dTNsTXRyNEgFfhZ/FTEBJEZXBTUeAHUKGFkDFwE8QixNViMsPTwALQ==' 'User' => [ 'username' => 'sitraka' 'email' => 'ratsimbasitraka@gmail.com' 'password' => '1234' ] ]
$_COOKIE = [ '_identity' => '854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s:49:\"[\"31\",\"5FrGIVMraKbUjcWvOsDERkMN7XGk5eyB\",2592000]\";' 'PHPSESSID' => '3ha4m1ob5kceeubrjufs98f3d3' '_csrf' => '91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes:32:\"pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e\";' ]
$_SERVER = [ 'HTTP_HOST' => 'localhost' 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0' 'HTTPACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,/_;q=0.8' 'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5' 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate' 'HTTP_REFERER' => 'http://localhost/basic/web/index.php/user/create' 'HTTP_COOKIE' => '_identity=854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s%3A49%3A%22%5B%2231%22%2C%225FrGIVMraKbUjcWvOsDERkMN7XGk5eyB%22%2C2592000%5D%22%3B; PHPSESSID=3ha4m1ob5kceeubrjufs98f3d3; _csrf=91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes%3A32%3A%22pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e%22%3B' 'HTTP_CONNECTION' => 'keep-alive' 'HTTP_CACHE_CONTROL' => 'max-age=0' 'CONTENT_TYPE' => 'application/x-www-form-urlencoded' 'CONTENT_LENGTH' => '163' 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' 'SERVER_SIGNATURE' => '
Apache/2.4.7 (Ubuntu) Server at localhost Port 80 ' 'SERVER_SOFTWARE' => 'Apache/2.4.7 (Ubuntu)' 'SERVER_NAME' => 'localhost' 'SERVER_ADDR' => '127.0.0.1' 'SERVER_PORT' => '80' 'REMOTE_ADDR' => '127.0.0.1' 'DOCUMENT_ROOT' => '/var/www' 'REQUEST_SCHEME' => 'http' 'CONTEXT_PREFIX' => '' 'CONTEXT_DOCUMENT_ROOT' => '/var/www' 'SERVER_ADMIN' => '[no address given]' 'SCRIPT_FILENAME' => '/var/www/basic/web/index.php' 'REMOTE_PORT' => '48051' 'GATEWAY_INTERFACE' => 'CGI/1.1' 'SERVER_PROTOCOL' => 'HTTP/1.1' 'REQUEST_METHOD' => 'POST' 'QUERY_STRING' => '' 'REQUEST_URI' => '/basic/web/index.php/user/create' 'SCRIPT_NAME' => '/basic/web/index.php' 'PATH_INFO' => '/user/create' 'PATH_TRANSLATED' => '/var/www/user/create' 'PHP_SELF' => '/basic/web/index.php/user/create' 'REQUEST_TIME_FLOAT' => 1415899318.449 'REQUEST_TIME' => 1415899318 ] 2014-11-13 20:43:12 [127.0.0.1][31][-][error][yii\web\HttpException:404] exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "CREATE".' in /var/www/basic/vendor/yiisoft/yii2/base/Module.php:461 Stack trace:Next exception 'yii\web\NotFoundHttpException' with message 'Unable to resolve the request "CREATE".' in /var/www/basic/vendor/yiisoft/yii2/web/Application.php:95 Stack trace:
2014-11-13 20:43:12 [127.0.0.1][31][-][info][application] $_COOKIE = [ '_identity' => '854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s:49:\"[\"31\",\"5FrGIVMraKbUjcWvOsDERkMN7XGk5eyB\",2592000]\";' 'PHPSESSID' => '7vt6vv6eu66gdf4t309am1ljf4' '_csrf' => '91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes:32:\"pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e\";' ]
$_SESSION = [ 'flash' => [] 'id' => '31' ]
$_SERVER = [ 'HTTP_HOST' => 'localhost' 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0' 'HTTPACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,/_;q=0.8' 'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5' 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate' 'HTTP_COOKIE' => '_identity=854a02187bab9b937e5520c7eab2009ded817fd5b82286e6b46c98798cb33310s%3A49%3A%22%5B%2231%22%2C%225FrGIVMraKbUjcWvOsDERkMN7XGk5eyB%22%2C2592000%5D%22%3B; PHPSESSID=7vt6vv6eu66gdf4t309am1ljf4; _csrf=91e984806b726594a75ab37b13dd3a1510254e7717153d627098f57649ad8faes%3A32%3A%22pMz2aC5l3dixjrABmjoZuNvd8eOaIN4e%22%3B' 'HTTP_CONNECTION' => 'keep-alive' 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' 'SERVER_SIGNATURE' => '
Apache/2.4.7 (Ubuntu) Server at localhost Port 80 ' 'SERVER_SOFTWARE' => 'Apache/2.4.7 (Ubuntu)' 'SERVER_NAME' => 'localhost' 'SERVER_ADDR' => '127.0.0.1' 'SERVER_PORT' => '80' 'REMOTE_ADDR' => '127.0.0.1' 'DOCUMENT_ROOT' => '/var/www' 'REQUEST_SCHEME' => 'http' 'CONTEXT_PREFIX' => '' 'CONTEXT_DOCUMENT_ROOT' => '/var/www' 'SERVER_ADMIN' => '[no address given]' 'SCRIPT_FILENAME' => '/var/www/basic/web/index.php' 'REMOTE_PORT' => '49440' 'GATEWAY_INTERFACE' => 'CGI/1.1' 'SERVER_PROTOCOL' => 'HTTP/1.1' 'REQUEST_METHOD' => 'GET' 'QUERY_STRING' => '' 'REQUEST_URI' => '/basic/web/index.php/CREATE' 'SCRIPT_NAME' => '/basic/web/index.php' 'PATH_INFO' => '/CREATE' 'PATH_TRANSLATED' => '/var/www/CREATE' 'PHP_SELF' => '/basic/web/index.php/CREATE' 'REQUEST_TIME_FLOAT' => 1415911392.861 'REQUEST_TIME' => 1415911392 ]check your code u have [['username, email'], 'unique'] need [['username', 'email'], 'unique']
rules look like this:
public function rules()
{
return [
[['username', 'email', 'password'], 'required'],
[['username','email'], 'unique', 'targetAttribute' => ['username', 'email']],
//['username', 'validateUsername', 'skipOnEmpty' => false, 'skipOnError' => false],
[['email'],'email'],
[['profil_picture', 'sexe', 'show_birthday', 'show_email'], 'integer'],
[['signup_date', 'birthday'], 'safe'],
[['biography'], 'string'],
[['username'], 'string', 'max' => 64],
[['email', 'password'], 'string', 'max' => 128]
];
}
when I fill fields, errors are not displayed. yet, username and email exist in the database.
have you clicked "Create"? client validation can not check for uniqueness. this is done on the server. you need to enable ajax validation if you want it directly.
The validation you saw is done on the client side which doesn't include the unique validation unless you configure it to be done via AJAX.
sitchaka try this:
public function rules()
{
return [
[['username', 'email', 'password'], 'required'],
['username', 'unique', 'targetClass' => '\common\models\User',
'message' => 'This username has already been taken.'],
['email', 'unique', 'targetClass' => '\common\models\User',
'message' => 'This email address has already been taken.'],
[['email'],'email'],
[['profil_picture', 'sexe', 'show_birthday', 'show_email'], 'integer'],
[['signup_date', 'birthday'], 'safe'],
[['biography'], 'string'],
[['username'], 'string', 'max' => 64],
[['email', 'password'], 'string', 'max' => 128]
];
}
Closed unless more information arrives.
I'm having the same problem .
See the problem context .
It occurs when I set the validator "unique " , " exist" or even when I do a custom function to do the validation .
When I submit the form, simply the page is blank. There is no error fired by Yii or browser console.
This same problem is occurring in both systems I'm developing in Yii . A MySQL , another for Oracle.
Follows the code :
public function rules()
{
return [
[['IDEXERCICIO', 'IDMES', 'IDORIGEMRECEITA', 'VALOR'], 'required'],
[['IDEXERCICIO', 'IDMES', 'IDORIGEMRECEITA'], 'integer'],
[['VALOR'], 'double', 'integerOnly'=>false, 'numberPattern'=>'/^\s(?:[1-9]\d{0,2}(?:.\d{3})|0)(?:,\d{1,2})?$/'],
[['OBSERVACAO'], 'safe'],
[['IDORIGEMRECEITA'], 'unicaOrigem'],
//[['IDORIGEMRECEITA'], 'unique', 'filter'=>'ATIVO=1'],
//[['IDORIGEMRECEITA'], 'exist'],
];
}
//-------------------------------------------------------------------------------------
public function unicaOrigem($attribute, $params) { $origem = self::find()->where( "IDORIGEMRECEITA = $this->IDORIGEMRECEITA AND ATIVO= 1")->one();
if($origem != NULL)
{
$this->addError('IDORIGEMRECEITA', 'record already exist' );
}
}
//----------------------------------------------------------------------------------------
Controller:
public function actionCreate() { $model = new RECEITA();
if($model->load(Yii::$app->request->post()))
{
$model->IDUSUARIO = Yii::$app->user->identity->IDUSUARIO;
$model->DATASISTEMA = Util::geraData();
if ($model->save())
{
return $this->redirect(['view', 'id' => $model->IDRECEITA]);
}
}
else
{
return $this->render('create', [
'model' => $model,
]);
}
}
I've tried the three forms and it still fails
the problem in your case is controller logic: you have one case that exists the action without printing anything.
change it to the following should work, this way you catch the case of failing validation by displaying the form with errors:
public function actionCreate()
{
$model = new RECEITA();
if($model->load(Yii::$app->request->post()))
{
$model->IDUSUARIO = Yii::$app->user->identity->IDUSUARIO;
$model->DATASISTEMA = Util::geraData();
if ($model->save())
{
return $this->redirect(['view', 'id' => $model->IDRECEITA]);
}
}
return $this->render('create', [
'model' => $model,
]);
}
Cebe, thank you for your answer. You are absolutely right.
Indeed, if the save () fails is not rendered anything;
I changed the code generated via CRUD Gii and not hearken to me that speaks of semantics.
Many thanks again.
Hello guys,
I'm trying to make unique mobile number on registration. So, I'm using Ajax validation. But I got blank page when I click on button save. Can you help me :)
Model:
public function rules()
{
return [
[['clicnic_idclicnic'], 'required'],
[['clicnic_idclicnic','day','month','year'], 'integer'],
[['birthday', 'first_login_date', 'last_login_date'], 'safe'],
[['first_name', 'last_name', 'street', 'plc', 'city', 'phone', 'mobile', 'email'], 'string', 'max' => 45],
[['mobile'],'unique'],
];
}
View
<?php $form = ActiveForm::begin([
'enableAjaxValidation'=>true,
]); ?>
.....
<?= $form->field($model, 'mobile')->textInput(['maxlength' => true]) ?>
Controller
public function actionCreate()
{
$model = new Patient();
if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())){
Yii::$app->response->format = 'json';
return ActiveForm::validate($model);
}
$year[] = null;
for ($i=1950; $i <= date("Y"); $i++) {
$year[$i] = $i;
}
$day[] = null;
for ($i=1; $i <= 31; $i++) {
$day[$i] = $i;
}
$month[] = null;
for ($i=1; $i <= 12; $i++) {
$month[$i] = $i;
}
if ($model->load(Yii::$app->request->post()) ) {
$model->birthday = $model->year.'-'.$model->month.'-'.$model->day;
if ($model->save()) {
return $this->redirect(['appointment/index','phonenum'=>$model->mobile]);
}
} else {
return $this->render('create', [
'model' => $model,
'clinic' => Clinic::find()->all(),
'day' => $day,
'month' => $month,
'year' => $year,
]);
}
}
What is the status-code of that blank page?
This is an automated comment, triggered by adding the label question
.
Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.
We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.
Please use one of the above mentioned resources to discuss the problem. If the result of the discussion turns out that there really is a bug in the framework, feel free to come back and provide information on how to reproduce the issue. This issue will be closed for now.
Redirect to this link: http://localhost:8080/klijent/web/index.php?r=patient%2Fcreate And Its blank. Confirm Form Resubmission "This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed. "
I think you are getting a blank page when save()
failed. Check you controller's action code, there is no logical branch with return
, when $model->save()
is false.
if ($model->load(Yii::$app->request->post()) ) { $model->birthday = $model->year.'-'.$model->month.'-'.$model->day; if ($model->save()) { return $this->redirect(['appointment/index','phonenum'=>$model->mobile]); } } else {
I can't create an user with unique username when i'm using the UniqueValidator class. Error: after submitting the form, I'm not redirected to the view page. I see a blank page on browser, and user was not created. it doesn't work even if I enter a username that doesn't yet exist in the database.