Advertisement
backlight0815

Dropzone Configuration and Form

Jul 21st, 2023
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.58 KB | Source Code | 0 0
  1. <form action="{{ route('checkout') }}" method="post" class="dropzone" id="receiptDropzone" enctype="multipart/form-data">
  2.     @csrf
  3.     @if($hasProducts)
  4.  
  5.     @foreach($cartItem as $item)
  6.     <input type="hidden" name="product_names[]" value="{{ $item->product->product_name }}">
  7.     <input type="hidden" name="product_prices[]" value="{{ $item->product->product_price }}">
  8.     <input type="hidden" id="hidden_quantity_{{ $item->id }}" name="quantities[]" value="{{ $item->quantity }}">
  9.     <input type="hidden" id="subtotal_{{ $item->id }}" name="subtotals[]" value="{{ $item->subtotal }}">
  10.     <input type="hidden" name="total_amount" value="{{ $total }}"> <!-- Assuming $total holds the total amount value -->
  11.  
  12.     @foreach($cartItem as $item)
  13.         <input type="hidden" name="cart_items[]" value="{{ json_encode(['product_id' => $item->product->id, 'quantity' => $item->quantity]) }}">
  14.     @endforeach
  15.  
  16. @endforeach
  17. @endif
  18.  
  19. <div class="fallback">
  20.     <input name="receipt" type="file" accept="image/jpeg,image/png,application/pdf">
  21. </div>
  22. <div class="dz-message needsclick">
  23.     <div class="mb-3">
  24.         <i class="display-4 text-muted ri-upload-cloud-2-line"></i>
  25.     </div>
  26.     <h4>Please upload your receipts.</h4>
  27. </div>
  28. <input type="hidden" name="total_amount" id="totalAmountInput">
  29.  
  30.  
  31. <div class="text-center mt-4">
  32.     <button type="submit" id="checkout" name="checkout_button" class="btn btn-warning btn-rounded waves-effect waves-light">Proceed to Checkout</button>
  33. </div>
  34. </form>
  35.  
  36.  
  37.  
  38. // <!-- Dropzone configuration -->
  39. Dropzone.autoDiscover = false;
  40.     const myDropzone = new Dropzone("#receiptDropzone", {
  41.  
  42.         autoProcessQueue: false, // Disable auto-upload
  43.         maxFiles: 1, // Allow only one file to be uploaded
  44.         addRemoveLinks: true,
  45.         renameFile: function(file) {
  46.                 var dt = new Date();
  47.                 var time = dt.getTime();
  48.                return time+file.name;
  49.             },
  50.  
  51.         // Other Dropzone options if needed
  52.         init: function () {
  53.             const submitButton = document.querySelector("#checkout");
  54.             const form = this; // "this" refers to the dropzone instance
  55.  
  56.             submitButton.addEventListener("click", function (event) {
  57.                 event.preventDefault();
  58.                 event.stopPropagation();
  59.                 form.processQueue(); // Process the queue manually
  60.  
  61.                 // Listen for the success event when all files are uploaded
  62.                 form.on("success", function (file, response) {
  63.                     // Assuming the response contains the notification data
  64.                     const notification = response.notification;
  65.                     if (notification && notification.message) {
  66.                         // Display the notification message using your preferred method
  67.                         alert(notification.message);
  68.                     }
  69.  
  70.                     // Redirect after successful checkout
  71.                     window.location.href = "{{ route('success.checkout') }}"; // Replace with your success page route
  72.                 });
  73.             });
  74.  
  75.  
  76.         // Listen to the addedfile event to handle file upload and saving
  77.         this.on("addedfile", function (file) {
  78.                     // Make sure to remove any previously uploaded file
  79.                     if (this.files.length > 1) {
  80.                         this.removeFile(this.files[0]);
  81.                     }
  82.  
  83.                     // Trigger the form submission when the user adds a file
  84.                     form.processQueue();
  85.                 });
  86.  
  87.  
  88.  
  89.  
  90.         },
  91.     });
  92.  
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement