/** * Creates a new Quiz model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Quiz(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function submit(Request $request) { if (!$request->ajax()) { throw new MethodNotAllowedHttpException(); } if (!$request->has('contact_data') || !$request->has('test_data')) { return response()->json(['result' => 'failure', 'message' => 'Sorry, something went wrong...']); } $contactData = $request->json('contact_data'); $testData = $request->json('test_data'); $quizEntry = new Quiz(['name' => $contactData['name'], 'email' => $contactData['email'], 'telephone' => $contactData['telephone'], 'test_type' => 'new_student', 'answered' => $testData['answered'], 'correct' => $testData['correct'], 'failed' => $testData['failed'], 'level_title' => $testData['level_title']]); $quizEntry->save(); return response()->json(['result' => 'success', 'redirect' => '/quiz/success'])->withCookie(cookie('passed_test_result', $testData['level_title'], 120)); }
/** * Creates a new Quiz model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Quiz(); $quizQuestion = new QuizQuestions(); $quizResults = new QuizResults(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($quizQuestion->saveQuizQuestions(Yii::$app->request->post('question'), $model['id'])) { if ($quizResults->saveQuizResults($model['id'], Yii::$app->request->post('results'))) { return $this->redirect(['view', 'id' => $model->id]); } } //return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }