title: Submitting formatted JSON with PHP form
body: <h1>Files</h1>
  
  <h2>index.php</h2>
  
  <pre><code>&lt;form name="postform" action="post.php" method="post" enctype="multipart/form-data"&gt;
  &lt;table class="postarea" id="postarea"&gt;
      &lt;tbody&gt;
  &lt;tr&gt;    &lt;td class="postblock"&gt;Date:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="startDate"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;    &lt;td class="postblock"&gt;Title:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="headline"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;    &lt;td class="postblock"&gt;Article:&lt;/td&gt;&lt;td&gt;&lt;textarea id="text" rows="5" cols="30" type="text" name="text"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt;
  &lt;tr&gt;    &lt;td class="assetblock"&gt;Image address:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="media"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;    &lt;td class="assetblock"&gt;Image caption:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="caption"&gt;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;    &lt;td class="postblock"&gt;&lt;/td&gt;&lt;td&gt; &lt;input type="submit" value="Submit Entry"&gt; &lt;/td&gt;    &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/form&gt;
  </code></pre>
  
  <h2>post.php</h2>
  
  <pre><code>&lt;?php
  // check if a form was submitted
  if( !empty( $_POST ) ){
  // convert form data to json format
  $json = json_encode( $_POST );
  // make sure there were no problems
  //if( json_last_error() != JSON_ERROR_NONE ){
      //exit;  // do your error handling here instead of exiting
  // }
  $file = 'entries.json';
  // write to file
  //   note: _server_ path, NOT "web address (url)"!
  file_put_contents( $file, $json, FILE_APPEND);
  }   
  </code></pre>
  
  <h1>Question</h1>
  
  <p>I am trying to create a form that will allow my users to add entries to the site. Entries are stored in a JSON file. I have created a form that submits to the JSON form and is formatted like this:</p>
  
  <pre><code>{"startDate":"example",
  "headline":"example",
  "text":"example",
  "media":"example",
  "caption":"example"}
  </code></pre>
  
  <p>Media and caption relate to an image, video or other multimedia, i need them to be stored as a separate object like the example below.</p>
  
  <pre><code> {"startDate":"example",
   "headline":"example",
   "text":"example",
   "asset" :{"media":"example",
            "caption":"example"}
   }
  </code></pre>