title: Save localstorage data to server using PHP
body: <p>I'm trying to implement a "save later" functionality in jquery using localstorage. the idea is saving every form event in localstorage and using a button to sync them and save to the server. </p>
  
  <p>I manage to save form data to localstorage and retrieve all the localstorage saved. Currently i'm struggling on how i can be able to submit specific values only to the server using PHP</p>
  
  <p>Here's my code for saving form data to localstorage</p>
  
  <pre><code>$('#systemInventory').on("submit", function(e) {
          e.preventDefault(); // prevent the form from attempting to send to the web server
          let $inputs = $('#systemInventory :input');
  
          let values = {};
          $inputs.each(function() {
              values[$(this).attr("name")] = $(this).val();
          });
  
          let title = 'systemInventory' + $.now();
          localStorage.setItem(title, JSON.stringify(values));
          $('#systemInventory')[0].reset();
          mdtoast('Successfully Saved',
              { type: mdtoast.INFO });
      });
  </code></pre>
  
  <p>and here's the one i used for retrieving data from the localstorage</p>
  
  <pre><code>function allStorage() {
  
      let values = [],
          keys = Object.keys(localStorage),
          i = keys.length;
  
      while ( i-- ) {
          values.push( localStorage.getItem(keys[i]) );
      }
  
      return values;
  }
  </code></pre>
  
  <p>Here's the one i'm trying to do to save specific data in the PHP storage</p>
  
  <pre><code>$.each(allStorage(), function (key, value) {
          let data = JSON.parse(value);
          console.log(data);
          $.ajax({
              url: "sync.php",
              method: 'POST',
              data: {data: data},
              success: function (response) {
                  console.log(response);
              },
              error: function (response) {
                  console.log(response);
              }
          });
      });
  </code></pre>
  
  <p>and my php code is </p>
  
  <pre><code>if (isset($_POST['data'])){
  
      foreach ($_POST['data'] as $key =&gt; $value){
  
          $data[] = array(
              $key =&gt; $value
          );
  
      }
  
      $dataForm = call_user_func_array('array_merge', $data);
  
      print_r($dataForm);
  
  
  //    print_r($data);
  
  }
  </code></pre>
  
  <p>When console logging all the localstorage saved i have this result
  <a href="https://i.stack.imgur.com/DdDdk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DdDdk.png" alt="enter image description here"></a></p>
  
  <p>and when clicking the sync, the one that is sending on the server i'm having this issue
  <a href="https://i.stack.imgur.com/wljhM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wljhM.png" alt="enter image description here"></a></p>
  
  <p>what i really want to happen is when i submit the localstorage data to php it will automatically form specific array for example</p>
  
  <pre><code>$data = array(
  'type'=&gt;'product',
  'beginning'=&gt;1,
  'delivery'=&gt;1
  
  );
  </code></pre>