From a8409f2bbe6a2f097244f5d712420e39fed31d5d Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Sun, 7 Sep 2025 18:13:55 +0330 Subject: [PATCH] more progress in qa --- src/Controller/QA/QAController.php | 276 ++++++++++++++++++++++++++-- src/Form/QA/QuestionFormType.php | 8 +- src/Service/AttachmentService.php | 50 ++++- templates/general/home.html.twig | 26 ++- templates/qa/ask_question.html.twig | 99 +++++++++- 5 files changed, 426 insertions(+), 33 deletions(-) diff --git a/src/Controller/QA/QAController.php b/src/Controller/QA/QAController.php index e6bd655..9fb6185 100644 --- a/src/Controller/QA/QAController.php +++ b/src/Controller/QA/QAController.php @@ -3,6 +3,7 @@ namespace App\Controller\QA; use App\Entity\Answer; +use App\Entity\Attachment; use App\Entity\Question; use App\Entity\QuestionTag; use App\Entity\QuestionTagRelation; @@ -136,9 +137,24 @@ class QAController extends AbstractController $form = $this->createForm(QuestionFormType::class, $question); $form->handleRequest($request); - + error_log('=== FORM DEBUG ==='); + error_log('Form isSubmitted: ' . ($form->isSubmitted() ? 'true' : 'false')); + error_log('Form isValid: ' . ($form->isSubmitted() ? ($form->isValid() ? 'true' : 'false') : 'not checked')); + error_log('Request method: ' . $request->getMethod()); + error_log('Request files count: ' . count($request->files->all())); + error_log('Form name: ' . $form->getName()); + error_log('Form block prefix: ' . $form->getConfig()->getType()->getBlockPrefix()); + error_log('Request data keys: ' . implode(', ', array_keys($request->request->all()))); + error_log('=== END FORM DEBUG ==='); if ($form->isSubmitted()) { + error_log('=== FORM SUBMITTED ==='); + error_log('Request method: ' . $request->getMethod()); + error_log('Content type: ' . $request->headers->get('Content-Type')); + error_log('Request files count: ' . count($request->files->all())); + error_log('Request data: ' . print_r($request->request->all(), true)); + error_log('Request files: ' . print_r($request->files->all(), true)); + // بررسی CSRF token - حذف شده چون Symfony خودش بررسی می‌کند // if (!$this->isCsrfTokenValid('question', $request->request->get('_token'))) { // $this->addFlash('error', 'CSRF token نامعتبر است.'); @@ -165,7 +181,13 @@ class QAController extends AbstractController // اگر form valid نیست، خطاها را نمایش بده if (!$form->isValid()) { - $this->addFlash('error', 'لطفاً تمام فیلدهای الزامی را پر کنید'); + $errors = []; + foreach ($form->getErrors(true) as $error) { + $errors[] = $error->getMessage(); + } + error_log('Form validation errors: ' . implode(', ', $errors)); + + $this->addFlash('error', 'لطفاً خطاهای فرم را برطرف کنید: ' . implode(', ', $errors)); $availableTags = $this->tagRepository->findActiveTags(); return $this->render('qa/ask_question.html.twig', [ 'form' => $form, @@ -174,33 +196,223 @@ class QAController extends AbstractController } // مدیریت پیوست فایل‌ها + error_log('=== STARTING FILE PROCESSING ==='); $attachments = $form->get('attachments')->getData(); error_log('Attachments from form: ' . print_r($attachments, true)); + error_log('Form attachments type: ' . gettype($attachments)); + error_log('Form attachments count: ' . (is_array($attachments) ? count($attachments) : 'not array')); // بررسی فایل‌های ارسال شده در request $uploadedFiles = $request->files->get('question_form')['attachments'] ?? []; error_log('Uploaded files from request: ' . print_r($uploadedFiles, true)); + error_log('Uploaded files type: ' . gettype($uploadedFiles)); + error_log('Uploaded files count: ' . (is_array($uploadedFiles) ? count($uploadedFiles) : 'not array')); - if ($attachments && count($attachments) > 0) { - error_log('Processing ' . count($attachments) . ' attachments from form'); - $uploadedAttachments = $this->attachmentService->uploadAttachments($attachments, $this->getUser(), $question); - error_log('Uploaded attachments: ' . print_r($uploadedAttachments, true)); - - foreach ($uploadedAttachments as $attachment) { - $question->addAttachment($attachment); - error_log('Added attachment to question: ' . $attachment->getOriginalFilename()); + // بررسی فایل‌های ارسال شده در request به صورت مستقیم + $uploadedFilesDirect = $request->files->get('question_form'); + error_log('Question form files structure: ' . print_r($uploadedFilesDirect, true)); + if (isset($uploadedFilesDirect['attachments'])) { + $uploadedFiles = $uploadedFilesDirect['attachments']; + error_log('Uploaded files from request (direct): ' . print_r($uploadedFiles, true)); + error_log('Direct uploaded files type: ' . gettype($uploadedFiles)); + error_log('Direct uploaded files count: ' . (is_array($uploadedFiles) ? count($uploadedFiles) : 'not array')); + } + + // بررسی مستقیم فایل‌های attachments + $directFiles = $request->files->get('attachments') ?? []; + error_log('Direct files from request: ' . print_r($directFiles, true)); + error_log('Direct files type: ' . gettype($directFiles)); + error_log('Direct files count: ' . (is_array($directFiles) ? count($directFiles) : 'not array')); + + // بررسی فایل‌های درون question_form + $questionFormFiles = $request->files->get('question_form') ?? []; + error_log('Question form files: ' . print_r($questionFormFiles, true)); + error_log('Question form files type: ' . gettype($questionFormFiles)); + error_log('Question form files count: ' . (is_array($questionFormFiles) ? count($questionFormFiles) : 'not array')); + + // بررسی تمام فایل‌های ارسال شده در request + $allFiles = $request->files->all(); + error_log('All files in request: ' . print_r($allFiles, true)); + error_log('All files type: ' . gettype($allFiles)); + error_log('All files count: ' . (is_array($allFiles) ? count($allFiles) : 'not array')); + + // بررسی دقیق‌تر ساختار فایل‌ها + foreach ($allFiles as $key => $value) { + error_log("File key: $key, type: " . gettype($value)); + if (is_array($value)) { + foreach ($value as $subKey => $subValue) { + error_log(" Sub key: $subKey, type: " . gettype($subValue)); + if (is_array($subValue)) { + foreach ($subValue as $subSubKey => $subSubValue) { + error_log(" Sub sub key: $subSubKey, type: " . gettype($subSubValue)); + if ($subSubValue instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) { + error_log(" Found UploadedFile: " . $subSubValue->getClientOriginalName()); + } + } + } elseif ($subValue instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) { + error_log(" Found UploadedFile: " . $subValue->getClientOriginalName()); + } + } + } elseif ($value instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) { + error_log(" Found UploadedFile: " . $value->getClientOriginalName()); } - } elseif ($uploadedFiles && count($uploadedFiles) > 0) { - error_log('Processing ' . count($uploadedFiles) . ' files from request'); - $uploadedAttachments = $this->attachmentService->uploadAttachments($uploadedFiles, $this->getUser(), $question); - error_log('Uploaded attachments from request: ' . print_r($uploadedAttachments, true)); + } + + $filesToProcess = []; + error_log('=== DETERMINING FILES TO PROCESS ==='); + + // اولویت با فایل‌های form + if ($attachments && count($attachments) > 0) { + $filesToProcess = $attachments; + error_log('Using attachments from form: ' . count($attachments)); + } + // سپس فایل‌های request + elseif ($uploadedFiles && count($uploadedFiles) > 0) { + $filesToProcess = $uploadedFiles; + error_log('Using files from request: ' . count($uploadedFiles)); + } + // سپس فایل‌های مستقیم + elseif ($directFiles && count($directFiles) > 0) { + $filesToProcess = $directFiles; + error_log('Using direct files: ' . count($directFiles)); + } + // سپس فایل‌های درون question_form + elseif (!empty($questionFormFiles) && isset($questionFormFiles['attachments'])) { + $filesToProcess = $questionFormFiles['attachments']; + error_log('Using files from question_form: ' . count($filesToProcess)); + } + // در نهایت بررسی تمام فایل‌های ارسال شده + elseif (!empty($allFiles)) { + foreach ($allFiles as $fieldName => $fieldFiles) { + error_log("Processing field: $fieldName"); + if (is_array($fieldFiles)) { + foreach ($fieldFiles as $file) { + if ($file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) { + $filesToProcess[] = $file; + error_log("Added file from allFiles: " . $file->getClientOriginalName()); + } + } + } elseif ($fieldFiles instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) { + $filesToProcess[] = $fieldFiles; + error_log("Added file from allFiles: " . $fieldFiles->getClientOriginalName()); + } + } + error_log('Using files from all request: ' . count($filesToProcess)); + } + + error_log('Final files to process count: ' . count($filesToProcess)); + error_log('Files to process: ' . print_r($filesToProcess, true)); + + // اگر هنوز فایلی پیدا نشده، بررسی دقیق‌تر + if (empty($filesToProcess)) { + error_log('=== NO FILES FOUND, CHECKING REQUEST STRUCTURE ==='); + $requestData = $request->request->all(); + $filesData = $request->files->all(); + error_log('Request data: ' . print_r($requestData, true)); + error_log('Files data: ' . print_r($filesData, true)); - foreach ($uploadedAttachments as $attachment) { - $question->addAttachment($attachment); - error_log('Added attachment to question: ' . $attachment->getOriginalFilename()); + // بررسی فایل‌های درون question_form + if (isset($filesData['question_form']['attachments'])) { + $filesToProcess = $filesData['question_form']['attachments']; + error_log('Found files in question_form[attachments]: ' . count($filesToProcess)); + } + + // بررسی فایل‌های درون question_form به صورت مستقیم + if (empty($filesToProcess) && isset($filesData['question_form'])) { + $questionFormData = $filesData['question_form']; + if (isset($questionFormData['attachments'])) { + $filesToProcess = $questionFormData['attachments']; + error_log('Found files in question_form directly: ' . count($filesToProcess)); + } + } + + // بررسی فایل‌های درون attachments + if (empty($filesToProcess) && isset($filesData['attachments'])) { + $filesToProcess = $filesData['attachments']; + error_log('Found files in attachments directly: ' . count($filesToProcess)); + } + + error_log('Final files to process after detailed check: ' . count($filesToProcess)); + } + + // اگر هنوز فایلی پیدا نشده، بررسی دقیق‌تر + if (empty($filesToProcess)) { + error_log('=== NO FILES FOUND, CHECKING REQUEST STRUCTURE ==='); + $requestData = $request->request->all(); + $filesData = $request->files->all(); + error_log('Request data: ' . print_r($requestData, true)); + error_log('Files data: ' . print_r($filesData, true)); + + // بررسی فایل‌های درون question_form + if (isset($filesData['question_form']['attachments'])) { + $filesToProcess = $filesData['question_form']['attachments']; + error_log('Found files in question_form[attachments]: ' . count($filesToProcess)); + } + + // بررسی فایل‌های درون question_form به صورت مستقیم + if (empty($filesToProcess) && isset($filesData['question_form'])) { + $questionFormData = $filesData['question_form']; + if (isset($questionFormData['attachments'])) { + $filesToProcess = $questionFormData['attachments']; + error_log('Found files in question_form directly: ' . count($filesToProcess)); + } + } + + // بررسی فایل‌های درون attachments + if (empty($filesToProcess) && isset($filesData['attachments'])) { + $filesToProcess = $filesData['attachments']; + error_log('Found files in attachments directly: ' . count($filesToProcess)); + } + + error_log('Final files to process after detailed check: ' . count($filesToProcess)); + } + + if (!empty($filesToProcess)) { + error_log('=== PROCESSING FILES ==='); + error_log('Processing ' . count($filesToProcess) . ' files'); + + // فیلتر کردن فایل‌های معتبر + $validFiles = []; + foreach ($filesToProcess as $index => $file) { + error_log("Processing file $index: " . gettype($file)); + if ($file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) { + error_log("File $index is UploadedFile: " . $file->getClientOriginalName()); + error_log("File $index error code: " . $file->getError()); + error_log("File $index size: " . $file->getSize()); + error_log("File $index MIME type: " . $file->getMimeType()); + + if ($file->getError() === UPLOAD_ERR_OK) { + $validFiles[] = $file; + error_log('Valid file found: ' . $file->getClientOriginalName() . ' (size: ' . $file->getSize() . ')'); + } else { + error_log('Invalid file: ' . $file->getClientOriginalName() . ' (error: ' . $file->getError() . ')'); + } + } else { + error_log('Invalid file type: ' . gettype($file) . ' (error: ' . ($file->getError() ?? 'unknown') . ')'); + } + } + + error_log('Valid files count: ' . count($validFiles)); + + if (!empty($validFiles)) { + error_log('=== UPLOADING ATTACHMENTS ==='); + $uploadedAttachments = $this->attachmentService->uploadAttachments($validFiles, $this->getUser(), $question); + error_log('Uploaded attachments count: ' . count($uploadedAttachments)); + error_log('Uploaded attachments: ' . print_r($uploadedAttachments, true)); + + foreach ($uploadedAttachments as $attachment) { + $question->addAttachment($attachment); + error_log('Added attachment to question: ' . $attachment->getOriginalFilename()); + } + + // ذخیره تغییرات در دیتابیس + $this->entityManager->flush(); + error_log('Question attachments saved to database'); + } else { + error_log('No valid files found to process'); } } else { - error_log('No attachments found in form data or request'); + error_log('No attachments found in any source'); } // حذف تمام تگ‌های قبلی برای این سوال @@ -232,6 +444,16 @@ class QAController extends AbstractController $this->entityManager->persist($question); $this->entityManager->flush(); + error_log('Question saved with ID: ' . $question->getId()); + error_log('Question attachments count after save: ' . $question->getAttachments()->count()); + + // بررسی فایل‌های ضمیمه در دیتابیس + $attachmentsInDb = $this->entityManager->getRepository(\App\Entity\Attachment::class)->findBy(['question' => $question]); + error_log('Attachments found in database for question ' . $question->getId() . ': ' . count($attachmentsInDb)); + foreach ($attachmentsInDb as $attachment) { + error_log('Database attachment: ' . $attachment->getOriginalFilename() . ' (ID: ' . $attachment->getId() . ')'); + } + $this->addFlash('success', 'سوال شما با موفقیت ثبت شد.'); return $this->redirectToRoute('qa_question_show', ['id' => $question->getId()]); } @@ -261,7 +483,23 @@ class QAController extends AbstractController $form = $this->createForm(AnswerFormType::class, $answer); $form->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()) { + if ($form->isSubmitted()) { + // بررسی اعتبارسنجی + if (!$form->isValid()) { + $errors = []; + foreach ($form->getErrors(true) as $error) { + $errors[] = $error->getMessage(); + } + error_log('Form validation errors: ' . implode(', ', $errors)); + + // نمایش خطاها به کاربر + $this->addFlash('error', 'لطفاً خطاهای فرم را برطرف کنید: ' . implode(', ', $errors)); + + return $this->render('qa/ask_question.html.twig', [ + 'form' => $form->createView(), + 'tags' => $this->entityManager->getRepository(QuestionTag::class)->findBy(['isActive' => true]) + ]); + } // مدیریت پیوست فایل‌ها $attachments = $form->get('attachments')->getData(); if ($attachments) { diff --git a/src/Form/QA/QuestionFormType.php b/src/Form/QA/QuestionFormType.php index 096b9a1..56bcbb3 100644 --- a/src/Form/QA/QuestionFormType.php +++ b/src/Form/QA/QuestionFormType.php @@ -92,7 +92,8 @@ class QuestionFormType extends AbstractType 'attr' => [ 'class' => 'form-control', 'accept' => '.jpg,.jpeg,.png,.gif,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt', - 'multiple' => true + 'multiple' => true, + 'name' => 'question_form[attachments][]' ], 'constraints' => [ new Assert\Count([ @@ -129,4 +130,9 @@ class QuestionFormType extends AbstractType 'data_class' => Question::class, ]); } + + public function getBlockPrefix(): string + { + return 'question_form'; + } } diff --git a/src/Service/AttachmentService.php b/src/Service/AttachmentService.php index 4a0b9f8..3a22393 100644 --- a/src/Service/AttachmentService.php +++ b/src/Service/AttachmentService.php @@ -34,15 +34,36 @@ class AttachmentService { $attachments = []; - foreach ($uploadedFiles as $uploadedFile) { + error_log('=== ATTACHMENT SERVICE START ==='); + error_log('AttachmentService: Processing ' . count($uploadedFiles) . ' files'); + error_log('AttachmentService: User ID: ' . $user->getId()); + error_log('AttachmentService: Question ID: ' . ($question ? $question->getId() : 'null')); + error_log('AttachmentService: Answer ID: ' . ($answer ? $answer->getId() : 'null')); + + foreach ($uploadedFiles as $index => $uploadedFile) { + error_log("AttachmentService: Processing file $index"); + error_log("AttachmentService: File type: " . gettype($uploadedFile)); + if ($uploadedFile instanceof UploadedFile) { + error_log("AttachmentService: File $index is UploadedFile: " . $uploadedFile->getClientOriginalName()); + error_log("AttachmentService: File $index error code: " . $uploadedFile->getError()); + error_log("AttachmentService: File $index size: " . $uploadedFile->getSize()); + error_log("AttachmentService: File $index MIME type: " . $uploadedFile->getMimeType()); + $attachment = $this->uploadSingleFile($uploadedFile, $user, $question, $answer); if ($attachment) { $attachments[] = $attachment; + error_log("AttachmentService: Successfully created attachment for file $index: " . $attachment->getOriginalFilename()); + } else { + error_log("AttachmentService: Failed to create attachment for file $index: " . $uploadedFile->getClientOriginalName()); } + } else { + error_log("AttachmentService: File $index is not UploadedFile: " . gettype($uploadedFile)); } } + error_log('AttachmentService: Total attachments created: ' . count($attachments)); + error_log('=== ATTACHMENT SERVICE END ==='); return $attachments; } @@ -51,13 +72,36 @@ class AttachmentService */ public function uploadSingleFile(UploadedFile $file, User $user, ?Question $question = null, ?Answer $answer = null): ?Attachment { + error_log('=== UPLOAD SINGLE FILE START ==='); + error_log('AttachmentService: Starting upload for: ' . $file->getClientOriginalName()); + error_log('AttachmentService: File size: ' . $file->getSize()); + error_log('AttachmentService: File MIME type: ' . $file->getMimeType()); + error_log('AttachmentService: File error code: ' . $file->getError()); + + // بررسی خطای آپلود + if ($file->getError() !== UPLOAD_ERR_OK) { + error_log('AttachmentService: Upload error: ' . $file->getError()); + return null; + } + $originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); $safeFilename = $this->slugger->slug($originalFilename); $fileName = $safeFilename . '-' . uniqid() . '.' . $file->guessExtension(); + error_log('AttachmentService: Target directory: ' . $this->targetDirectory); + error_log('AttachmentService: Generated filename: ' . $fileName); + try { + // اطمینان از وجود دایرکتوری + if (!is_dir($this->targetDirectory)) { + mkdir($this->targetDirectory, 0755, true); + error_log('AttachmentService: Created directory: ' . $this->targetDirectory); + } + $file->move($this->targetDirectory, $fileName); + error_log('AttachmentService: File moved successfully'); } catch (FileException $e) { + error_log('AttachmentService: File move failed: ' . $e->getMessage()); return null; } @@ -71,14 +115,18 @@ class AttachmentService if ($question) { $attachment->setQuestion($question); + error_log('AttachmentService: Set question ID: ' . $question->getId()); } if ($answer) { $attachment->setAnswer($answer); + error_log('AttachmentService: Set answer ID: ' . $answer->getId()); } $this->entityManager->persist($attachment); $this->entityManager->flush(); + error_log('AttachmentService: Attachment entity created and saved with ID: ' . $attachment->getId()); + error_log('=== UPLOAD SINGLE FILE END ==='); return $attachment; } diff --git a/templates/general/home.html.twig b/templates/general/home.html.twig index 3483b04..f0ef254 100644 --- a/templates/general/home.html.twig +++ b/templates/general/home.html.twig @@ -51,7 +51,7 @@
0
-
کسب و کار فعال
+
هزار کسب‌و‌کار
@@ -625,13 +625,20 @@ entries.forEach(entry => { if (entry.isIntersecting) { const target = parseInt(entry.target.dataset.target); - animateCounter(entry.target, target); + // بررسی اینکه آیا شمارنده قبلاً انیمیشن شده یا نه + if (!entry.target.classList.contains('animated')) { + entry.target.classList.add('animated'); + animateCounter(entry.target, target); + } observer.unobserve(entry.target); } }); }, { threshold: 0.5 }); counters.forEach(counter => { + // ریست کردن شمارنده به صفر + counter.textContent = '0'; + counter.classList.remove('animated'); observer.observe(counter); }); } @@ -683,12 +690,21 @@ }); } - // اجرا پس از بارگذاری صفحه - document.addEventListener('DOMContentLoaded', function() { + // تابع اصلی برای اجرای انیمیشن‌ها + function initHomeAnimations() { handleScrollAnimation(); animateSteps(); animateFloatingElements(); initHoverEffects(); - }); + } + + // اجرا پس از بارگذاری صفحه + document.addEventListener('DOMContentLoaded', initHomeAnimations); + + // اجرا پس از تغییر صفحه با Turbo + document.addEventListener('turbo:load', initHomeAnimations); + + // اجرا پس از بازگشت به صفحه با Turbo + document.addEventListener('turbo:render', initHomeAnimations); {% endblock %} diff --git a/templates/qa/ask_question.html.twig b/templates/qa/ask_question.html.twig index c58b339..85f95f9 100644 --- a/templates/qa/ask_question.html.twig +++ b/templates/qa/ask_question.html.twig @@ -1020,21 +1020,80 @@ window.QuestionFormClasses.FileManager = class FileManager { return; } + console.log('=== UPDATING FILE INPUT ==='); + console.log('Selected files count:', this.selectedFiles.length); + console.log('Selected files:', this.selectedFiles); + // تنظیم فایل‌ها در input اصلی try { - const dt = new DataTransfer(); - this.selectedFiles.forEach(fileData => { - dt.items.add(fileData.file); - }); - this.fileInput.files = dt.files; + // ایجاد یک input جدید برای هر فایل + const form = this.fileInput.closest('form'); + if (form) { + console.log('Form found:', form); + + // حذف input های قبلی + const existingInputs = form.querySelectorAll('input[type="file"][name*="attachments"]'); + console.log('Existing inputs count:', existingInputs.length); + existingInputs.forEach(input => { + if (input !== this.fileInput) { + input.remove(); + } + }); + + // اضافه کردن فایل‌ها به input اصلی + if (this.selectedFiles.length > 0) { + console.log('Adding files to input...'); + + // استفاده از DataTransfer اگر پشتیبانی شود + if (typeof DataTransfer !== 'undefined') { + console.log('Using DataTransfer API'); + const dt = new DataTransfer(); + this.selectedFiles.forEach((fileData, index) => { + console.log(`Adding file ${index}:`, fileData.file.name); + dt.items.add(fileData.file); + }); + this.fileInput.files = dt.files; + console.log('DataTransfer files count:', this.fileInput.files.length); + } else { + console.log('Using alternative method'); + // روش جایگزین: ایجاد input های جداگانه + this.selectedFiles.forEach((fileData, index) => { + console.log(`Creating input for file ${index}:`, fileData.file.name); + const newInput = document.createElement('input'); + newInput.type = 'file'; + newInput.name = 'question_form[attachments][]'; + newInput.style.display = 'none'; + + // ایجاد FileList جدید + const fileList = new DataTransfer(); + fileList.items.add(fileData.file); + newInput.files = fileList.files; + + form.appendChild(newInput); + }); + } + } else { + console.log('No files to add'); + } + } else { + console.error('Form not found'); + } console.log('Updated file input with', this.selectedFiles.length, 'files'); console.log('File input files:', this.fileInput.files.length); + + // بررسی نهایی فایل‌ها + for (let i = 0; i < this.fileInput.files.length; i++) { + console.log(`Final file ${i}:`, this.fileInput.files[i].name); + } + } catch (e) { - console.warn('DataTransfer not supported:', e); - // در صورت عدم پشتیبانی، فایل‌ها را در متغیر سراسری ذخیره می‌کنیم + console.error('Error updating file input:', e); + // در صورت خطا، فایل‌ها را در متغیر سراسری ذخیره می‌کنیم window.selectedFiles = this.selectedFiles; } + + console.log('=== FILE INPUT UPDATE COMPLETE ==='); } } } @@ -1100,13 +1159,17 @@ function initializeQuestionForm() { } function handleFormSubmit(e) { + console.log('=== FORM SUBMIT START ==='); + // اطمینان از اینکه تگ‌ها به فرم اضافه شده‌اند if (window.questionFormManager.tagManager) { + console.log('Updating tag manager...'); // ابتدا تگ‌ها را به فرم اضافه کن window.questionFormManager.tagManager.updateHiddenInput(); // اعتبارسنجی تگ‌ها if (!window.questionFormManager.tagManager.validateTags()) { + console.log('Tag validation failed'); e.preventDefault(); e.stopPropagation(); return false; @@ -1115,7 +1178,17 @@ function handleFormSubmit(e) { // اطمینان از اینکه فایل‌ها به فرم اضافه شده‌اند if (window.questionFormManager.fileManager) { + console.log('Updating file manager...'); window.questionFormManager.fileManager.updateFileInput(); + + // بررسی نهایی فایل‌ها + const fileInput = e.target.querySelector('input[type="file"]'); + if (fileInput) { + console.log('Final file input files:', fileInput.files.length); + for (let i = 0; i < fileInput.files.length; i++) { + console.log('File', i, ':', fileInput.files[i].name, fileInput.files[i].size); + } + } } // غیرفعال کردن Turbo برای این فرم @@ -1131,6 +1204,18 @@ function handleFormSubmit(e) { if (window.questionFormManager.fileManager) { console.log('Selected files in JavaScript:', window.questionFormManager.fileManager.selectedFiles.length); } + + // بررسی تمام فایل‌های موجود در فرم + const allFileInputs = form.querySelectorAll('input[type="file"]'); + console.log('All file inputs in form:', allFileInputs.length); + allFileInputs.forEach((input, index) => { + console.log(`File input ${index}:`, input.name, input.files.length); + for (let i = 0; i < input.files.length; i++) { + console.log(` File ${i}:`, input.files[i].name); + } + }); + + console.log('=== FORM SUBMIT END ==='); } // اجرا در بارگذاری صفحه