MyBB Community Forums

Full Version: Attachment not saved when added after prior AJAX removal of attachment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
These steps to reproduce assume:
  1. That attachments are enabled and that the current user has the right to upload+remove them.
  2. That Javascript is enabled.
Steps to reproduce:
  1. Either load up a new thread with newthread.php, or load up a post for editing with editpost.php, or load up a new reply in a thread with newreply.php.
  2. Beside "New Attachment:" click "Choose Files" and select a valid file to upload.
  3. Click "Add Attachment". The page reloads and the attachment appears in the list.
  4. Beside the attachment, click "Remove" and then click "Yes" on the approval dialogue that pops up. The attachment fades out and is removed from the page.
  5. Repeat steps #2 and #3. The page reloads but the added attachment is not present and has not been saved.
Expected behaviour at step #5: The page reloads and the attachment appears in the list.

I've investigated this problem, and concluded that the simplest way to solve it is to insert this new line of code (properly indented) at line number 132 of jscripts/post.js:

document.input.attachmentaid.value = '';

Edit: although a more appropriate solution (deleting rather than adding code) is to simply remove from those three files the first occurrence in each of the code:

!$mybb->get_input('attachmentaid', MyBB::INPUT_INT) && 
Hmm, I think that I got few similar reports for this in my board...

Please open a PR, seems reasonable. I will test Smile thx!
I've got a combined fix for the issue described in the OP, plus Editing posts with JS disabled to manage attachments #3675 on GitHub, and Thread Modes $_FILES['attachment'] instead of $_FILES['attachments'] #3886. Happy for me to submit the whole thing as a single PR?

Nvm. Best I split them up, plus, you've already submitted a valid PR for #3886, so no need to include that.
Just send one PR, the second one is already waiting for mybb devs to merge Smile thx!
Can confirm this issue.
PR submitted:

https://github.com/mybb/mybb/pull/3926/files

@Eldenroot, I chose to submit it as a single PR mostly because additional changes were made to the same lines as your PR, and it was simplest just to make all the changes at once.