DmitrMakeev commited on
Commit
51b8202
·
verified ·
1 Parent(s): fd17183

Update pages.html

Browse files
Files changed (1) hide show
  1. pages.html +87 -0
pages.html CHANGED
@@ -452,6 +452,93 @@ z-index: 1000; /* Убедитесь, что кнопка находится п
452
  }
453
  });
454
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
  // Добавление кнопки для открытия редактора кода
456
  const pn = editor.Panels;
457
  const panelViews = pn.addPanel({
 
452
  }
453
  });
454
 
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+ // Создаем новый тип компонента для формы
463
+ editor.Components.addType('custom-form', {
464
+ model: {
465
+ defaults: {
466
+ // HTML-код формы
467
+ content: `
468
+ <form id="custom-form">
469
+ <input type="text" name="name" placeholder="Your Name" required>
470
+ <input type="email" name="email" placeholder="Your Email" required>
471
+ <input type="tel" name="phone" placeholder="Your Phone" required>
472
+ <label><input type="checkbox" name="subscribe" value="yes"> I agree to receive newsletters</label>
473
+ <button type="submit">Submit</button>
474
+ </form>
475
+ `,
476
+ // Скрипт для обработки отправки формы
477
+ script: function(props) {
478
+ const form = this.querySelector('#custom-form');
479
+ form.addEventListener('submit', function(event) {
480
+ event.preventDefault();
481
+ const formData = new FormData(form);
482
+ const data = {};
483
+ formData.forEach((value, key) => {
484
+ data[key] = value;
485
+ });
486
+ fetch(props.submitUrl, {
487
+ method: 'POST',
488
+ headers: {
489
+ 'Content-Type': 'application/json'
490
+ },
491
+ body: JSON.stringify(data)
492
+ })
493
+ .then(response => response.json())
494
+ .then(data => {
495
+ console.log('Success:', data);
496
+ })
497
+ .catch((error) => {
498
+ console.error('Error:', error);
499
+ });
500
+ });
501
+ },
502
+ // Свойства, которые будут передаваться в скрипт
503
+ 'script-props': ['submitUrl'],
504
+ // Настройки для изменения URL отправки
505
+ traits: [
506
+ {
507
+ type: 'text',
508
+ name: 'submitUrl',
509
+ label: 'Submit URL',
510
+ changeProp: true
511
+ }
512
+ ]
513
+ }
514
+ }
515
+ });
516
+
517
+ // Создаем блок для компонента формы
518
+ editor.Blocks.add('custom-form-block', {
519
+ label: 'Custom Form',
520
+ content: { type: 'custom-form' },
521
+ });
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
  // Добавление кнопки для открытия редактора кода
543
  const pn = editor.Panels;
544
  const panelViews = pn.addPanel({