0

I use Firefox add-on called "Session Manager" to save and restore sessions. I have simple php + html form:

<form id="form_id" enctype="multipart/form-data" method="post" action="upload.php">
    <input id="name$key" type="text" placeholder="Name" name="name[]" value="$name">
    <input type="file" name="fileToUpload[]" id="fileToUpload$key">
    <input id="submit" name="submit" type="submit" value="Submit">
</form>

When I restore form inputs data with "Session Manager" I can see all data I need. When I click the "Submit" button, data have empty $_POST.

What can I do to not lose this data?

Maybe to use some JQuery or session_start(); $_SESSION?

Blue
  • 22,608
  • 7
  • 62
  • 92
kostya572
  • 169
  • 2
  • 21
  • there's no php/jquery here, check for errors – Funk Forty Niner Jan 14 '17 at 23:57
  • Can you post the contents of upload.php? That will help us debug your code.. – Runny Yolk Jan 15 '17 at 00:10
  • @RunnyYolk upload.php has simple - `echo "
    ";var_dump($_POST);var_dump($_FILES);echo "
    ";exit();` If i post without "Session Manager" add-on everything ok, but when i restore session with "Session Manager", post data is empty.
    – kostya572 Jan 15 '17 at 00:36

2 Answers2

1

Firefox add-on "Session Manager" seems to work incorrect if html <form> setted with attribute enctype="multipart/form-data". If you want to send some files through POST use <form> attribute enctype="application/x-www-form-urlencoded" in conjunction with php copy(). That's not clean solution. Maybe there could be other solutions with enctype="multipart/form-data", maybe some expirements with form accept-charset could give you better results.

kostya572
  • 169
  • 2
  • 21
0

The Session Manager plugin in Firefox is not at all related to PHP sessions. Same word, entirely different meanings.

A Firefox session is your browser tabs and the websites they are accessing. A PHP session relates to a user session on a specific website.

Most likely the data you are seeing "saved" in the forms is just field data that is saved in Firefox only, for the sole purpose of making data re-entry faster. It is not yet actually "in" the form fields, but saved in Firefox (only, not on the website) in order to make easier the re-entry of frequently typed data.

When you lose a connection to a website, you lose the data typed in the fields. Refreshing the page loses the data typed in the fields. There is no work-around for this, it's just how it is.

If you have further questions, please ask in comments below this answer.

Edit:

Re-thinking, it may be possible to achieve some kind of solution using a javascript/jQuery (please, jQuery) solution that involves detected when fields are exited (blur()) and subsequent grabbing of the data and saving in localStorage.

References:

https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API

http://www.w3schools.com/html/html5_webstorage.asp

When is localStorage cleared?

What is the max size of localStorage values?

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • without addon everything works and it posts without a problem. You right about that data not actualy saves "in" the form fields. Maybe there is some ajax code that can reinitialize dom with that data? Logically i can't believe if i see typed data in forms so i can't send correct POST data. – kostya572 Jan 15 '17 at 00:44
  • You might be looking for some client-side code such as [localStorage](http://archive.oreilly.com/oreillyschool/courses/javascript2/IntroLocalStorage.html) and [see this also](http://stackoverflow.com/a/19861332/1447509) *(localStorage is like Cookies ver 2 - simpler to use, and can hold up to 10Mb per website, as of FF45+)* – cssyphus Jan 15 '17 at 02:29
  • I've found that main error caused by `enctype="multipart/form-data"` if I don't send files, "Session Manager" works well. But I don't know the reason for that. I've tried to change encodings `accept-charset="UTF-8"`, but it doesn't worked for me. – kostya572 Jan 15 '17 at 03:41
  • Solved this problem with removing `enctype="multipart/form-data"` and using default `enctype="application/x-www-form-urlencoded"`. Then i used php `copy()` instead of `move_uploaded_file()`. Thank you for your cooperation. – kostya572 Jan 15 '17 at 04:37
  • THANK YOU for posting your solution. Please post it as an answer and select it as the correct answer. My answer will serve as something for future readers to check, but yours is the solution. Please post a reply to this comment once your answer is posted and you are guaranteed of at least one upvote. – cssyphus Jan 15 '17 at 15:32
  • I've posted answer, only tomorrow I can accept it. Thanks Stack Exchange community, you help me every day to find answers. Only the problem is the language barrier to describe precisely the problem of question for that reason there are a lot of downvotes. – kostya572 Jan 15 '17 at 22:42