I am trying to make my website work with both js enbaled and when it's not. I've just started. So I'm starting with the registration of a new user. I have a link to register and it works fine.
I also have a JS version where the form is in a modal box.
user controller
/**
* register via modal box
*/
public function actionJsRegister()
{
// get js modal #id
$js = '$("#create").modal("show")';
// register js code
$this->getView()->registerJs($js);
$model = new User();
$userType = $model->getUserTypeDropDown();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
// set flash
Yii::$app->session->setFlash('success', 'Account Created, please check your inbox');
// send activation email
return $this->redirect(['site/index']);
} else {
return $this->render('jsCreate', [
'model' => $model,
'userType' => $userType,
]);
}
}
1 - Is that controller ok as code?
2 - How would I make my link in the navbar show just the regular version if no js is enabled and the modal version if it is enabled?
Kudos to you for building with progressive enhancement! Your site will be far more robust for it.
I can't speak specifically for the controller code as I have not used Yii2 (though logically it looks sensible), but I can discuss the second question about the navigation. The easiest way to do it is to have the navbar exist by default and then use JavaScript to hijack the page, converting the navbar into a modal.