本文整理汇总了PHP中yii\bootstrap\ActiveForm::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveForm::validate方法的具体用法?PHP ActiveForm::validate怎么用?PHP ActiveForm::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\bootstrap\ActiveForm
的用法示例。
在下文中一共展示了ActiveForm::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveData
public function saveData()
{
if ($this->model->load(Yii::$app->request->post())) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
// perform AJAX validation
echo ActiveForm::validate($this->model);
Yii::$app->end();
return '';
}
/** @var User|bool $registeredUser */
$registeredUser = $this->model->register();
if ($registeredUser !== false) {
$module = UsersModule::module();
// login registered user if there's no need in confirmation
$shouldLogin = $module->allowLoginInactiveAccounts || $module->emailConfirmationNeeded === false;
if ($module->emailConfirmationNeeded === true && $registeredUser->is_active) {
$shouldLogin = true;
}
if ($shouldLogin && $registeredUser->login(UsersModule::module()->loginDuration)) {
$returnUrl = Yii::$app->request->get('returnUrl');
if ($returnUrl !== null) {
return $this->controller->redirect($returnUrl);
}
}
return $this->controller->goBack();
}
}
return '';
}
示例2: actionUser
public function actionUser()
{
//make a db con or go back
$db = new InstallConfig();
try {
$db->con();
} catch (\yii\db\Exception $e) {
return $this->render('config', array('model' => $db, "error" => "No DB"));
}
if (!User::find()->All() == null) {
return $this->redirect('?r=install/finish');
//Yii::$app->end();
}
//user
$model = new User();
$model->scenario = 'create';
$model->language = 'he_il';
$model->timezone = 'Asia/Jerusalem';
if ($model->load(Yii::$app->request->post())) {
//$model->save();
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\bootstrap\ActiveForm::validate($model);
}
if ($model->save()) {
$this->redirect('?r=install/finish');
}
}
return $this->render('user', array('model' => $model));
}
示例3: actionUser
/**
* регистрация юзера по имейл
* если регистрация для покупки, то передаются параметры рекомендатель и урл
* @param type $affiliate_id
* @param type $url_id
* @return type
* @throws \yii\web\NotFoundHttpException
*/
public function actionUser($affiliate_id = null, $url_id = null)
{
$request = Yii::$app->request;
$model = new \app\models\registration\UserForm();
if ($request->isAjax && $model->load($request->post())) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load($request->post()) && $model->validate()) {
$user = User::findByUsername($model->email);
if (!$user) {
$user = $model->save();
}
$user->setCookie();
if ($affiliate_id === null || $url_id === null) {
Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту');
return $this->goHome();
}
$url = Url::findOne($url_id);
if (!$url) {
throw new \yii\web\NotFoundHttpException('Урл не найден');
}
$user->purchase($affiliate_id, $url);
return $this->redirect($url->link);
}
return $this->render('user', ['model' => $model]);
}
示例4: actionValidateOptionsForm
public function actionValidateOptionsForm()
{
$cOptFrm = new OptionsForm();
if (Yii::$app->request->isAjax && $cOptFrm->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($cOptFrm);
}
}
示例5: run
public function run()
{
$request = Yii::$app->getRequest();
$this->modelComment = new BlogComment();
if ($request->isAjax && $this->modelComment->load($request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
$errors = ActiveForm::validate($this->modelComment);
echo json_encode($errors);
}
}
示例6: actionRegister
public function actionRegister()
{
$model = new SignupForm();
$model->scenario = 'short_register';
if (\Yii::$app->request->isAjax && \Yii::$app->request->isPost) {
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(\Yii::$app->request->post()) && $model->signup()) {
print_r($model->getAttributes());
die;
}
return $this->render("register", ['model' => $model]);
}
示例7: actionPassword_change
public function actionPassword_change()
{
$model = new \app\models\Form\PasswordNew();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->action(\Yii::$app->user->identity)) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
} else {
return $this->render(['model' => $model]);
}
}
示例8: actionInfo
public function actionInfo($id = '')
{
$model = new MenuForm();
if (Yii::$app->request->isAjax && \Yii::$app->request->post('ajax', '') == 'info-form' && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post())) {
$model->save();
Yii::$app->end();
}
$model->update($id);
return $this->render('info', ['model' => $model]);
}
示例9: actionRegister
public function actionRegister()
{
$model = new SignupForm();
//$model->scenario = 'short_register';
if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
}
if ($model->load(Yii::$app->request->post()) && $model->signup()) {
Yii::$app->session->setFlash('success', 'Success register');
}
return $this->render('register', ['model' => $model]);
}
示例10: actionLogin
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
return $this->render('login_form', ['model' => $model]);
}
示例11: run
public function run()
{
Yii::setAlias('@unclead-examples', realpath(__DIR__ . '/../'));
$model = new ExampleModel();
$request = Yii::$app->getRequest();
if ($request->isPost && $request->post('ajax') !== null) {
$model->load(Yii::$app->request->post());
Yii::$app->response->format = Response::FORMAT_JSON;
$result = ActiveForm::validate($model);
return $result;
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
}
return $this->controller->render('@unclead-examples/views/example.php', ['model' => $model]);
}
示例12: actionContact
public function actionContact()
{
$this->layout = 'inner';
$model = new ContactForm();
if (Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$body = " <div>Body: <b> " . $model->body . " </b></div>";
$body .= " <div>Email: <b> " . $model->email . " </b></div>";
Yii::$app->common->sendMail($model->subject, $body);
print 'Send success';
die;
}
return $this->render('contact', ['model' => $model]);
}
示例13: actionConfigure
public function actionConfigure()
{
$settings = PaypalSettings::find()->one();
if ($settings->load(Yii::$app->request->post())) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($settings);
}
if ($settings->save()) {
PaypalSubscriptionExpress::deleteAll();
PaypalExpressPayment::deleteAll();
Yii::$app->getSession()->setFlash('success', 'Paypal settings updated succesfully');
return $this->refresh();
}
}
return $this->render('configure', ['settings' => $settings]);
}
示例14: run
/**
* Registro de empresa
* @return array|string|Response
*/
public function run()
{
if (!\Yii::$app->user->isGuest) {
return $this->controller->redirect('/');
}
$model = new EmpresaForm();
$model->scenario = EmpresaForm::ESCENARIO_CREAR;
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post())) {
if ($franquicia = $model->registrar()) {
return $this->controller->render('registro-creado', ['model' => $franquicia]);
}
}
return $this->controller->render('crear-cuenta', ['model' => $model]);
}
示例15: actionOrder
public function actionOrder()
{
$model = new OrderForm();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
$result = ActiveForm::validate($model);
Yii::$app->response->format = Response::FORMAT_JSON;
if (!empty($result)) {
return $result;
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail(Setting::get('admin_email'))) {
return 'success';
} else {
return 'error';
}
}
}
}