DmitrMakeev commited on
Commit
0651fb6
·
verified ·
1 Parent(s): e7a0125

Update pages.html

Browse files
Files changed (1) hide show
  1. pages.html +18 -12
pages.html CHANGED
@@ -511,29 +511,35 @@ editor.Components.addType('custom-form', {
511
  const form = this.querySelector('#contactForm');
512
  form.addEventListener('submit', function(event) {
513
  event.preventDefault();
514
- const data = {
515
- name: document.getElementById('name').value,
516
- email: document.getElementById('email').value,
517
- phone: document.getElementById('phone').value,
518
- options: document.getElementById('options').value,
519
- newsletter: document.getElementById('newsletter').checked
520
- };
521
  if (!props.submitUrl) {
522
  console.error('Submit URL is not defined');
523
  return;
524
  }
 
 
525
  fetch(props.submitUrl, {
526
  method: 'POST',
527
  headers: {
528
- 'Content-Type': 'application/json'
529
  },
530
- body: JSON.stringify(data)
 
 
 
 
 
 
 
531
  })
532
- .then(response => response.json())
533
  .then(data => {
534
- console.log('Success:', data);
 
 
 
535
  })
536
- .catch((error) => {
537
  console.error('Error:', error);
538
  });
539
  });
 
511
  const form = this.querySelector('#contactForm');
512
  form.addEventListener('submit', function(event) {
513
  event.preventDefault();
514
+ const formData = new FormData(form);
515
+ const data = new URLSearchParams(formData).toString();
 
 
 
 
 
516
  if (!props.submitUrl) {
517
  console.error('Submit URL is not defined');
518
  return;
519
  }
520
+ console.log('Form Data:', data); // Выводим данные формы в консоль
521
+ console.log('Submit URL:', props.submitUrl); // Выводим URL в консоль
522
  fetch(props.submitUrl, {
523
  method: 'POST',
524
  headers: {
525
+ 'Content-Type': 'application/x-www-form-urlencoded'
526
  },
527
+ body: data
528
+ })
529
+ .then(response => {
530
+ console.log('Ответ сервера:', response); // Проверка ответа сервера
531
+ if (!response.ok) {
532
+ throw new Error('Ошибка HTTP: ' + response.status);
533
+ }
534
+ return response.json();
535
  })
 
536
  .then(data => {
537
+ console.log('Данные от сервера:', data); // Вывод ответа сервера в консоль
538
+ if (data.redirect) {
539
+ window.location.href = data.redirect;
540
+ }
541
  })
542
+ .catch(error => {
543
  console.error('Error:', error);
544
  });
545
  });