Guest User

Untitled

a guest
Jan 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <form name="postform" action="post.php" method="post" enctype="multipart/form-data">
  2. <table class="postarea" id="postarea">
  3. <tbody>
  4. <tr> <td class="postblock">Date:</td><td><input type="text" name="startDate"></td></tr>
  5. <tr> <td class="postblock">Title:</td><td><input type="text" name="headline"></td></tr>
  6. <tr> <td class="postblock">Article:</td><td><textarea id="text" rows="5" cols="30" type="text" name="text"></textarea> </td> </tr>
  7. <tr> <td class="assetblock">Image address:</td><td><input type="text" name="media"></td></tr>
  8. <tr> <td class="assetblock">Image caption:</td><td><input type="text" name="caption"></td></tr>
  9.  
  10. <tr> <td class="postblock"></td><td> <input type="submit" value="Submit Entry"> </td> </tr>
  11. </tbody>
  12. </table>
  13. </form>
  14. </form>
  15.  
  16. <?php
  17. // check if a form was submitted
  18. if( !empty( $_POST ) ){
  19. // convert form data to json format
  20. $json = json_encode( $_POST );
  21. // make sure there were no problems
  22. //if( json_last_error() != JSON_ERROR_NONE ){
  23. //exit; // do your error handling here instead of exiting
  24. // }
  25. $file = 'entries.json';
  26. // write to file
  27. // note: _server_ path, NOT "web address (url)"!
  28. file_put_contents( $file, $json, FILE_APPEND);
  29. }
  30.  
  31. {"startDate":"example",
  32. "headline":"example",
  33. "text":"example",
  34. "media":"example",
  35. "caption":"example"}
  36.  
  37. {"startDate":"example",
  38. "headline":"example",
  39. "text":"example",
  40. "asset" :{"media":"example",
  41. "caption":"example"}
  42. }
  43.  
  44. <?php
  45. // check if a form was submitted
  46. if( !empty( $_POST ) ){
  47.  
  48. // convert form data to json format
  49. $postArray = array(
  50. "startDate" => $_POST['startDate'],
  51. "headline" => $_POST['headline'],
  52. "text" => $_POST['text'],
  53. "asset" => array(
  54. "media" => $_POST["media"],
  55. "caption" => $_POST['caption']
  56. )
  57. ); //you might need to process any other post fields you have..
  58.  
  59. $json = json_encode( $postArray );
  60. // make sure there were no problems
  61. //if( json_last_error() != JSON_ERROR_NONE ){
  62. //exit; // do your error handling here instead of exiting
  63. // }
  64. $file = 'entries.json';
  65. // write to file
  66. // note: _server_ path, NOT "web address (url)"!
  67. file_put_contents( $file, $json, FILE_APPEND);
  68. }
Add Comment
Please, Sign In to add comment