diff --git a/upload/install/controller/install/step_3.php b/upload/install/controller/install/step_3.php index e5fc78798d5..e22b8db30d8 100644 --- a/upload/install/controller/install/step_3.php +++ b/upload/install/controller/install/step_3.php @@ -92,23 +92,23 @@ public function save(): void { } if (!$this->request->post['db_hostname']) { - $json['db_hostname'] = $this->language->get('error_db_hostname'); + $json['error']['db_hostname'] = $this->language->get('error_db_hostname'); } if (!$this->request->post['db_username']) { - $json['db_username'] = $this->language->get('error_db_username'); + $json['error']['db_username'] = $this->language->get('error_db_username'); } if (!$this->request->post['db_database']) { - $json['db_database'] = $this->language->get('error_db_database'); + $json['error']['db_database'] = $this->language->get('error_db_database'); } if (!$this->request->post['db_port']) { - $json['db_port'] = $this->language->get('error_db_port'); + $json['error']['db_port'] = $this->language->get('error_db_port'); } if ($this->request->post['db_prefix'] && preg_match('/[^a-z0-9_]/', $this->request->post['db_prefix'])) { - $json['db_prefix'] = $this->language->get('error_db_prefix'); + $json['error']['db_prefix'] = $this->language->get('error_db_prefix'); } $db_drivers = [ @@ -118,33 +118,35 @@ public function save(): void { ]; if (!in_array($this->request->post['db_driver'], $db_drivers)) { - $json['db_driver'] = $this->language->get('error_db_driver'); - } else { + $json['error']['db_driver'] = $this->language->get('error_db_driver'); + } + + if (!$json) { try { $db = new \Opencart\System\Library\DB($this->request->post['db_driver'], html_entity_decode($this->request->post['db_hostname'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_username'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_database'], ENT_QUOTES, 'UTF-8'), $this->request->post['db_port'], $this->request->post['db_ssl_key'], $this->request->post['db_ssl_cert'], $this->request->post['db_ssl_ca']); } catch (\Exception $e) { - $json['warning'] = $e->getMessage(); + $json['error']['warning'] = $e->getMessage(); } } if (!$this->request->post['username']) { - $json['username'] = $this->language->get('error_username'); + $json['error']['username'] = $this->language->get('error_username'); } if (!oc_validate_email($this->request->post['email'])) { - $json['email'] = $this->language->get('error_email'); + $json['error']['email'] = $this->language->get('error_email'); } if (!$this->request->post['password']) { - $json['password'] = $this->language->get('error_password'); + $json['error']['password'] = $this->language->get('error_password'); } if (!is_writable(DIR_OPENCART . 'config.php')) { - $json['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'config.php!'; + $json['error']['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'config.php!'; } if (!is_writable(DIR_OPENCART . 'admin/config.php')) { - $json['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'admin/config.php!'; + $json['error']['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'admin/config.php!'; } if (!$json) { diff --git a/upload/install/view/template/install/step_2.twig b/upload/install/view/template/install/step_2.twig index 1bfe64f511f..5daa091366c 100644 --- a/upload/install/view/template/install/step_2.twig +++ b/upload/install/view/template/install/step_2.twig @@ -264,6 +264,8 @@ $('#form-step-2').on('submit', function(e) { $('#button-continue').prop('disabled', false); }, success: function(json) { + console.log(json); + $('.alert-dismissible').remove(); if (json['redirect']) { diff --git a/upload/install/view/template/install/step_3.twig b/upload/install/view/template/install/step_3.twig index 1109952e64b..2a0a37abc02 100644 --- a/upload/install/view/template/install/step_3.twig +++ b/upload/install/view/template/install/step_3.twig @@ -10,7 +10,7 @@
{{ text_step_3 }}
-
+
{{ text_db_connection }}
@@ -26,7 +26,8 @@
- {% for driver in drivers %} {% endfor %} @@ -34,32 +35,39 @@
- + +
- + +
- + +
- + +
- + +
- + +
- + +
@@ -141,8 +149,10 @@ $('#input-db-driver').trigger('change'); $('#form-step-3').on('submit', function(e) { e.preventDefault(); + var element = this; + $.ajax({ - url: 'index.php?route=install/step_2.save&language=' + $('#input-language').val(), + url: 'index.php?route=install/step_3.save&language=' + $('#input-language').val(), type: 'post', data: $('#form-step-3').serialize(), dataType: 'json', @@ -153,14 +163,26 @@ $('#form-step-3').on('submit', function(e) { $('#button-continue').prop('disabled', false); }, success: function(json) { + console.log(json); + $('.alert-dismissible').remove(); + $(element).find('.is-invalid').removeClass('is-invalid'); + $(element).find('.invalid-feedback').removeClass('d-block'); if (json['redirect']) { location = json['redirect']; } if (json['error']) { - $('#form-step-2').prepend('
' + json['error'] + '
'); + if (json['error']['warning']) { + $('#form-step-3').prepend('
' + json['error']['warning'] + '
'); + } + + + for (key in json['error']) { + $('#input-' + key.replaceAll('_', '-')).addClass('is-invalid').find('.form-control, .form-select, .form-check-input, .form-check-label').addClass('is-invalid'); + $('#error-' + key.replaceAll('_', '-')).html(json['error'][key]).addClass('d-block'); + } } }, error: function(xhr, ajaxOptions, thrownError) {