public function actionValidarformularioajax() { $model = new ValidarFormularioAjax(); $msg = null; if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { $msg = "Enhora buena formulario enviado correctamente"; \Yii::$app->getSession()->setFlash('success', $msg); $model->nombre = null; $model->email = null; } else { $model->getErrors(); } } return $this->render('validarformularioajax', ['model' => $model]); }
public function actionValidarformularioajax() { $model = new ValidarFormularioAjax(); $msg = null; if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { //Por ejemplo hacer una consulta a una base de datos $msg = "Enhorabuena formulario enviado correctamente"; $model->nombre = null; $model->email = null; } else { $model->getErrors(); } } return $this->render("validarformularioajax", ['model' => $model, 'msg' => $msg]); }
public function actionValidarformularioajax() { $model = new ValidarFormularioAjax(); $msg = null; if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { // Consulta a base de Datos $msg = "Form eviado con exito"; $model->nombre = null; $model->email = null; } else { $model->getErrors(); } return $this->render("validarformularioajax", ['model' => $model, 'msg' => '']); }
public function actionValidarformularioajax() { $model = new ValidarFormularioAjax(); $msg = null; if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { //acciones = consultar/registrar $msg = "Enhorabuena, Formulario enviado exitosamente"; $model->nombre = null; $model->email = null; } else { $model->getErrors(); } } return $this->render("validarformularioajax", ['model' => $model, 'mensaje' => $msg]); }