Answer the question
In order to leave comments, you need to log in
How to make step by step registration form in Yii2?
How to implement step by step user registration form. The user can leave the registration at any step (close the tab in the browser), but then, returning, the data entered by him earlier will be saved.
So far, I have made it so that the form fields are shown to the user in turn, by clicking "registration" the data is written to the database.
But so far I don’t understand at all how to make sure that when the page is reloaded, the form and the step are in place
. I took the script for displaying the form here https://jsfiddle.net/aradul/2ce92efj/
If possible, answer in great detail please ..
Answer the question
In order to leave comments, you need to log in
do everything through js processing of the entire form you do in the model. you save the data in cookies through js, you specify any period.
After registering any data in the database, write the user's user ID into the cookie. At the next login, if there is a database with such a user ID, pull them out and fill them in.
I see 2 ways
1) on Yii2
class User extends ActiveRecord
{
const SCENARIO_STEP1 = 'step1';
const SCENARIO_STEP2 = 'step2';
...
public function scenarios()
{
return [
self::SCENARIO_STEP1 => ['attr1', 'attr2'],
self::SCENARIO_STEP2 => ['attr3', 'attr4', 'attr5'],
];
}
...
public function actionStep1()
{
$model = new OrderWizard();
$model->setScenario(OrderWizard::SCENARIO_STEP1);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['step-2', 'id' => $model->id]);
} else {
return $this->render('step-1', [
'model' => $model,
]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question