<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport"…
- User
header { background-color: #002f87; color: #fff; padding: 20px; text-align: center; } main { max-width: 800px; margin: 40px auto; background-color: #fff; padding: 30px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h1 { margin-top: 0; color: #002f87; } fieldset { border: none; margin-bottom: 20px; } legend { font-weight: bold; margin-bottom: 10px; color: #002f87; } label { display: block; margin-top: 15px; } input[type="text"], input[type="email"], input[type="number"], textarea { width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #ccc; border-radius: 4px; } textarea { resize: vertical; min-height: 100px; } button { background-color: #00a3e0; color: #fff; padding: 12px 25px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } button:hover { background-color: #008cc0; }<label for="address">Address:</label> <input type="text" id="address" name="address" required> <label for="contact">Contact Number:</label> <input type="text" id="contact" name="contact" required> <label for="email">Email Address:</label> <input type="email" id="email" name="email" required> </fieldset> <fieldset> <legend>Section 2: Claim Details</legend> <label for="euroducting_order">Euroducting Order Number:</label> <input type="text" id="euroducting_order" name="euroducting_order" required> <label for="customer_order">Customer Order Number:</label> <input type="text" id="customer_order" name="customer_order" required> <label for="delivery_note">Delivery Note:</label> <input type="text" id="delivery_note" name="delivery_note"> <label for="invoice">Invoice:</label> <input type="text" id="invoice" name="invoice"> <label for="item">Item:</label> <input type="text" id="item" name="item" required> <label for="quantity">Quantity:</label> <input type="number" id="quantity" name="quantity" required min="1"> <label for="description">Description of Product Defects:</label> <textarea id="description" name="description" required></textarea> <input type="hidden" id="remote_address" name="remote_address" readonly> </fieldset> <button type="submit">Submit Claim</button> </form>dodaj do tego skryptu obsługę dynamicznego dołączania plików do formularza i obsługę tego formularza po stronie serwera w php
Assistant
Oto ulepszona wersja formularza z dynamicznym dołączaniem plików i przykładową obsługą po stronie serwera w PHP:
HTML (z dynamicznym dołączaniem plików):
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Claim Form - Euroducting</title> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; } header { background-color: #002f87; color: #fff; padding: 20px; text-align: center; } main { max-width: 800px; margin: 40px auto; background-color: #fff; padding: 30px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h1 { margin-top: 0; color: #002f87; } fieldset { border: none; margin-bottom: 20px; } legend { font-weight: bold; margin-bottom: 10px; color: #002f87; } label { display: block; margin-top: 15px; } input[type="text"], input[type="email"], input[type="number"], textarea { width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #ccc; border-radius: 4px; } textarea { resize: vertical; min-height: 100px; } button { background-color: #00a3e0; color: #fff; padding: 12px 25px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } button:hover { background-color: #008cc0; } .file-upload { margin-top: 20px; } .file-list { margin-top: 10px; } .file-item { display: flex; align-items: center; margin-bottom: 5px; } .file-item button { margin-left: 10px; padding: 5px 10px; background-color: #ff4444; font-size: 12px; } .file-item button:hover { background-color: #cc0000; } #add-file { background-color: #4CAF50; margin-top: 10px; } #add-file:hover { background-color: #45a049; } </style> </head> <body> <header> <h1>Euroducting - Product Claim Form</h1> </header> <main> <form action="submit_claim.php" method="POST" enctype="multipart/form-data"> <fieldset> <legend>Section 1: Contact Information</legend> <label for="name">Name:</label> <input type="text" id="name" name="name" required> <label for="address">Address:</label> <input type="text" id="address" name="address" required> <label for="contact">Contact Number:</label> <input type="text" id="contact" name="contact" required> <label for="email">Email Address:</label> <input type="email" id="email" name="email" required> </fieldset> <fieldset> <legend>Section 2: Claim Details</legend> <label for="euroducting_order">Euroducting Order Number:</label> <input type="text" id="euroducting_order" name="euroducting_order" required> <label for="customer_order">Customer Order Number:</label> <input type="text" id="customer_order" name="customer_order" required> <label for="delivery_note">Delivery Note:</label> <input type="text" id="delivery_note" name="delivery_note"> <label for="invoice">Invoice:</label> <input type="text" id="invoice" name="invoice"> <label for="item">Item:</label> <input type="text" id="item" name="item" required> <label for="quantity">Quantity:</label> <input type="number" id="quantity" name="quantity" required min="1"> <label for="description">Description of Product Defects:</label> <textarea id="description" name="description" required></textarea> </fieldset> <fieldset> <legend>Section 3: Attachments</legend> <div class="file-upload"> <div id="file-container"> <input type="file" name="attachments[]" multiple> </div> <button type="button" id="add-file">Add More Files</button> <div id="file-list" class="file-list"></div> </div> </fieldset> <input type="hidden" id="remote_address" name="remote_address" readonly> <button type="submit">Submit Claim</button> </form> </main> <script> // Pobierz adres IP użytkownika fetch('https://api.ipify.org?format=json') .then(response => response.json()) .then(data => { document.getElementById('remote_address').value = data.ip; }); // Dynamiczne dodawanie pól do załączników document.getElementById('add-file').addEventListener('click', function() { const container = document.getElementById('file-container'); const newInput = document.createElement('input'); newInput.type = 'file'; newInput.name = 'attachments[]'; newInput.multiple = true; container.appendChild(newInput); }); // Wyświetlanie listy wybranych plików document.querySelectorAll('input[type="file"]').forEach(input => { input.addEventListener('change', function() { const fileList = document.getElementById('file-list'); fileList.innerHTML = ''; // Przejdź przez wszystkie pola file document.querySelectorAll('input[type="file"]').forEach(fileInput => { if (fileInput.files.length > 0) { for (let i = 0; i < fileInput.files.length; i++) { const fileItem = document.createElement('div'); fileItem.className = 'file-item'; const fileName = document.createElement('span'); fileName.textContent = fileInput.files[i].name; const removeBtn = document.createElement('button'); removeBtn.type = 'button'; removeBtn.textContent = 'Remove'; removeBtn.addEventListener('click', function() { // Utwórz nową listę plików bez usuniętego pliku const dataTransfer = new DataTransfer(); for (let j = 0; j < fileInput.files.length; j++) { if (j !== i) { dataTransfer.items.add(fileInput.files[j]); } } fileInput.files = dataTransfer.files; // Ponownie wyświetl listę plików input.dispatchEvent(new Event('change')); }); fileItem.appendChild(fileName); fileItem.appendChild(removeBtn); fileList.appendChild(fileItem); } } }); }); }); </script> </body> </html>PHP (submit_claim.php) - obsługa formularza:
<?php // Ustawienia $uploadDir = 'uploads/'; $maxFileSize = 5 * 1024 * 1024; // 5MB $allowedTypes = ['image/jpeg', 'image/png', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']; // Sprawdź czy folder upload istnieje, jeśli nie - utwórz if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); } // Inicjalizacja tablicy na wyniki $response = [ 'success' => false, 'message' => '', 'errors' => [] ]; // Sprawdź metodę żądania if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Walidacja danych formularza $requiredFields = ['name', 'address', 'contact', 'email', 'euroducting_order', 'customer_order', 'item', 'quantity', 'description']; foreach ($requiredFields as $field) { if (empty($_POST[$field])) { $response['errors'][$field] = 'This field is required'; } } // Walidacja emaila if (!filter_var($_POST['email'], FILTER_VALIDATE
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.