-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-form.html
More file actions
319 lines (276 loc) · 15.7 KB
/
test-form.html
File metadata and controls
319 lines (276 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Тестовая форма - CRM Integration</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.4.0/css/all.min.css">
<!-- intl-tel-input -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@19.5.6/build/css/intlTelInput.css">
<script src="https://cdn.jsdelivr.net/npm/intl-tel-input@19.5.6/build/js/intlTelInput.min.js"></script>
<!-- Phone Config -->
<script src="js/phone-config.js"></script>
</head>
<body class="bg-gray-100">
<div class="container mx-auto px-4 py-12">
<div class="max-w-2xl mx-auto">
<!-- Header -->
<div class="bg-white rounded-lg shadow-lg p-6 mb-6">
<h1 class="text-3xl font-bold text-gray-800 mb-2">
<i class="fas fa-vial text-blue-600 mr-2"></i>
Тестовая форма для CRM
</h1>
<p class="text-gray-600">
Проверка интеграции с CRM через api.php
</p>
</div>
<!-- Instructions -->
<div class="bg-blue-50 border-l-4 border-blue-600 rounded-r-lg p-6 mb-6">
<h2 class="font-bold text-lg text-blue-900 mb-2">
<i class="fas fa-info-circle mr-2"></i>
Инструкция по тестированию
</h2>
<ol class="list-decimal list-inside space-y-2 text-blue-800">
<li>Заполните форму тестовыми данными</li>
<li>Выберите страну в телефонном поле</li>
<li>Нажмите "Отправить тестовый лид"</li>
<li>Проверьте редирект на success.php или error.php</li>
<li>Проверьте логи: api_log.txt и duplicates_leads.log</li>
</ol>
</div>
<!-- Test Form -->
<div class="bg-white rounded-lg shadow-lg p-8">
<h2 class="text-2xl font-bold text-gray-800 mb-6">
Форма для отправки тестового лида
</h2>
<form id="test-form" class="space-y-4">
<!-- Name -->
<div>
<label class="block text-gray-700 font-semibold mb-2">
<i class="fas fa-user mr-2 text-blue-600"></i>
Имя *
</label>
<input type="text" name="name" required
class="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:border-blue-600 focus:outline-none"
placeholder="Иван Тестовый"
value="Иван Тестовый">
</div>
<!-- Phone -->
<div>
<label class="block text-gray-700 font-semibold mb-2">
<i class="fas fa-phone mr-2 text-blue-600"></i>
Телефон *
</label>
<input type="tel" id="test-phone" name="phone" required
class="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:border-blue-600 focus:outline-none"
placeholder="">
<p class="text-sm text-gray-500 mt-1">
<i class="fas fa-info-circle mr-1"></i>
Телефон будет отформатирован как: КОД_СТРАНЫ + НОМЕР (без "+")
</p>
</div>
<!-- Email -->
<div>
<label class="block text-gray-700 font-semibold mb-2">
<i class="fas fa-envelope mr-2 text-blue-600"></i>
Email *
</label>
<input type="email" name="email" required
class="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:border-blue-600 focus:outline-none"
placeholder="test@example.com"
value="test@example.com">
</div>
<!-- Broker -->
<div>
<label class="block text-gray-700 font-semibold mb-2">
<i class="fas fa-building mr-2 text-blue-600"></i>
Брокер (опционально)
</label>
<input type="text" name="broker"
class="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:border-blue-600 focus:outline-none"
placeholder="Название брокера"
value="TestBroker">
</div>
<!-- Amount -->
<div>
<label class="block text-gray-700 font-semibold mb-2">
<i class="fas fa-dollar-sign mr-2 text-blue-600"></i>
Сумма (опционально)
</label>
<input type="text" name="amount"
class="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:border-blue-600 focus:outline-none"
placeholder="10000"
value="10000">
</div>
<!-- Comment -->
<div>
<label class="block text-gray-700 font-semibold mb-2">
<i class="fas fa-comment mr-2 text-blue-600"></i>
Комментарий (опционально)
</label>
<textarea name="comment" rows="3"
class="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:border-blue-600 focus:outline-none"
placeholder="Дополнительная информация">Тестовый лид из test-form.html</textarea>
</div>
<!-- Hidden fields -->
<input type="hidden" name="aff" value="3">
<input type="hidden" name="offer" value="cordoba-legal-new">
<input type="hidden" name="country" value="" class="country-field">
<input type="hidden" name="phonecc" value="" class="phonecc-field">
<input type="hidden" name="form_type" value="test">
<!-- Submit Button -->
<button type="submit" id="submit-btn"
class="w-full bg-gradient-to-r from-blue-600 to-blue-700 text-white py-4 rounded-lg font-bold text-lg shadow-lg hover:shadow-xl transition">
<i class="fas fa-paper-plane mr-2"></i>
Отправить тестовый лид
</button>
</form>
<!-- Response Display -->
<div id="response" class="mt-6 hidden">
<!-- Response will be shown here -->
</div>
</div>
<!-- Debug Info -->
<div class="bg-gray-800 text-white rounded-lg shadow-lg p-6 mt-6">
<h3 class="font-bold text-lg mb-3">
<i class="fas fa-bug mr-2 text-yellow-400"></i>
Debug Info
</h3>
<div id="debug-info" class="space-y-2 text-sm font-mono">
<p>Waiting for form submission...</p>
</div>
</div>
<!-- Back to home -->
<div class="text-center mt-6">
<a href="index.html" class="text-blue-600 hover:text-blue-700 font-semibold">
<i class="fas fa-arrow-left mr-2"></i>
Вернуться на главную
</a>
</div>
</div>
</div>
<script>
// Initialize phone input
const phoneInput = document.getElementById('test-phone');
let iti;
if (phoneInput) {
iti = window.intlTelInput(phoneInput, {
initialCountry: 'de',
preferredCountries: ['de', 'gb', 'lt', 'lv'],
onlyCountries: ['de', 'gb', 'lt', 'lv', 'se', 'be', 'it'],
utilsScript: 'https://cdn.jsdelivr.net/npm/intl-tel-input@19.5.6/build/js/utils.js',
separateDialCode: false,
formatOnDisplay: true,
nationalMode: false,
autoPlaceholder: 'aggressive'
});
phoneInput.intlTelInputInstance = iti;
}
// Form submission
document.getElementById('test-form').addEventListener('submit', async function(e) {
e.preventDefault();
const form = this;
const submitBtn = document.getElementById('submit-btn');
const responseDiv = document.getElementById('response');
const debugDiv = document.getElementById('debug-info');
// Get form data
const formData = new FormData(form);
// Get phone country data
if (iti) {
const countryData = iti.getSelectedCountryData();
formData.set('phonecc', countryData.dialCode || '');
formData.set('country', countryData.iso2.toUpperCase() || 'DE');
// Update hidden fields
form.querySelector('.phonecc-field').value = countryData.dialCode || '';
form.querySelector('.country-field').value = countryData.iso2.toUpperCase() || 'DE';
}
// Debug info
debugDiv.innerHTML = `
<p><span class="text-yellow-400">Status:</span> Отправка...</p>
<p><span class="text-yellow-400">Name:</span> ${formData.get('name')}</p>
<p><span class="text-yellow-400">Phone:</span> ${formData.get('phone')}</p>
<p><span class="text-yellow-400">Email:</span> ${formData.get('email')}</p>
<p><span class="text-yellow-400">Country:</span> ${formData.get('country')}</p>
<p><span class="text-yellow-400">Phone CC:</span> ${formData.get('phonecc')}</p>
<p><span class="text-yellow-400">Broker:</span> ${formData.get('broker')}</p>
<p><span class="text-yellow-400">Amount:</span> ${formData.get('amount')}</p>
<p><span class="text-yellow-400">Form Type:</span> ${formData.get('form_type')}</p>
`;
// Show loading
submitBtn.disabled = true;
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Отправка...';
responseDiv.classList.add('hidden');
try {
const response = await fetch('api.php', {
method: 'POST',
body: formData
});
const responseText = await response.text();
// Update debug info
debugDiv.innerHTML += `
<p class="mt-2"><span class="text-yellow-400">HTTP Status:</span> ${response.status}</p>
<p><span class="text-yellow-400">Response:</span></p>
<pre class="bg-gray-900 p-2 rounded mt-1 text-xs overflow-x-auto">${responseText}</pre>
`;
// Check if redirected
if (response.redirected) {
debugDiv.innerHTML += `<p class="mt-2 text-green-400">✅ Редирект на: ${response.url}</p>`;
// Show success message before redirect
responseDiv.innerHTML = `
<div class="bg-green-50 border-l-4 border-green-600 rounded-r-lg p-4">
<h3 class="font-bold text-green-900 mb-2">✅ Успешно отправлено!</h3>
<p class="text-green-800">Сейчас произойдет редирект на страницу успеха...</p>
</div>
`;
responseDiv.classList.remove('hidden');
// Redirect after 2 seconds
setTimeout(() => {
window.location.href = response.url;
}, 2000);
return;
}
// Parse JSON response
try {
const jsonResponse = JSON.parse(responseText);
if (response.ok) {
responseDiv.innerHTML = `
<div class="bg-green-50 border-l-4 border-green-600 rounded-r-lg p-4">
<h3 class="font-bold text-green-900 mb-2">✅ Успешно отправлено!</h3>
<p class="text-green-800">Лид успешно отправлен в CRM.</p>
<pre class="bg-white p-2 rounded mt-2 text-xs overflow-x-auto">${JSON.stringify(jsonResponse, null, 2)}</pre>
</div>
`;
} else {
throw new Error(jsonResponse.error || 'Unknown error');
}
} catch (parseError) {
// Not JSON, show raw text
responseDiv.innerHTML = `
<div class="bg-yellow-50 border-l-4 border-yellow-600 rounded-r-lg p-4">
<h3 class="font-bold text-yellow-900 mb-2">⚠️ Необычный ответ</h3>
<p class="text-yellow-800 mb-2">Ответ не в формате JSON</p>
<pre class="bg-white p-2 rounded text-xs overflow-x-auto">${responseText}</pre>
</div>
`;
}
responseDiv.classList.remove('hidden');
} catch (error) {
debugDiv.innerHTML += `<p class="mt-2 text-red-400">❌ Error: ${error.message}</p>`;
responseDiv.innerHTML = `
<div class="bg-red-50 border-l-4 border-red-600 rounded-r-lg p-4">
<h3 class="font-bold text-red-900 mb-2">❌ Ошибка отправки</h3>
<p class="text-red-800">${error.message}</p>
</div>
`;
responseDiv.classList.remove('hidden');
} finally {
submitBtn.disabled = false;
submitBtn.innerHTML = '<i class="fas fa-paper-plane mr-2"></i>Отправить тестовый лид';
}
});
</script>
</body>
</html>