custom-field-page.html.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php if (!defined('HTMLY')) die('HTMLy'); ?>
  2. <h2 class="post-index"><?php echo i18n('custom_fields');?>: Page</h2>
  3. <br>
  4. <?php
  5. $field = array();
  6. $field_file= 'content/data/field/page.json';
  7. if (file_exists($field_file)) {
  8. $field = file_get_contents($field_file, true);
  9. }
  10. ?>
  11. <!-- Preview Section -->
  12. <div id="form-preview"></div>
  13. <br>
  14. <!-- Form Input Section -->
  15. <div class="form-group" id="form-input">
  16. <span class="d-block mt-1" id="input-status"></span>
  17. <br>
  18. <div class="row">
  19. <div class="col">
  20. <label for="type">Form type</label>
  21. <select id="type" class="form-control">
  22. <option value="text">Text</option>
  23. <option value="textarea">Textarea</option>
  24. <option value="checkbox">Checkbox</option>
  25. <option value="select">Select</option>
  26. </select>
  27. </div>
  28. <div class="col">
  29. <label for="label">Label</label>
  30. <input type="text" class="form-control" id="label" placeholder="Label (required)">
  31. </div>
  32. <div class="col">
  33. <label for="name">Name</label>
  34. <input type="text" class="form-control" id="name" placeholder="Name (required)">
  35. </div>
  36. <div class="col">
  37. <label for="value">Value</label>
  38. <input type="text" class="form-control" id="value" placeholder="Value (optional)">
  39. </div>
  40. <div class="col">
  41. <label for="info">Info</label>
  42. <input type="text" class="form-control" id="info" placeholder="Field Info (optional)">
  43. </div>
  44. <div class="col">
  45. <label for="add-field">Operations</label>
  46. <button id="add-field" class="btn btn-primary">Add Field</button>
  47. </div>
  48. </div>
  49. <span class="d-block mt-1"><small><em>No spaces for <code>Name</code> input. Underscores and dashes allowed</em></small></span>
  50. <div id="options-container" style="display: none;">
  51. <div class="row">
  52. <div class="col-sm-6">
  53. <h5 class="mt-2">Options</h5>
  54. <div id="option-list"></div>
  55. <button id="add-option" class="btn btn-primary btn-xs mt-1">Add Option</button>
  56. <span class="d-block mt-1"><small><em>No spaces for select and option <code>Value</code> input. Underscores and dashes allowed</em></small></span>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- Form submit Section -->
  62. <button class="btn btn-primary" id="saveButton"><?php echo i18n('save');?></button>
  63. <br><br>
  64. <!-- JSON Output Section -->
  65. <details>
  66. <summary style="padding:10px; margin-bottom:10px; <?php echo ((config('admin.theme') === 'light' || is_null(config('admin.theme'))) ? "background-color: #E4EBF1;" : "background-color: rgba(255,255,255,.1);");?>">JSON Output</summary>
  67. <textarea id="json-output" name="page-field" style="field-sizing: content;" rows="20" class="form-control text" readonly></textarea>
  68. </details>
  69. <br><br>
  70. <script>
  71. const fields = <?php print_r($field);?>;
  72. $("#saveButton").click(function(){
  73. var data = $('#json-output').val();
  74. $.ajax({
  75. type: 'POST',
  76. url: '<?php echo site_url();?>admin/field/page',
  77. dataType: 'json',
  78. data: {'json': data},
  79. success: function (response) {
  80. alert(response.message);
  81. location.reload();
  82. },
  83. });
  84. });
  85. </script>
  86. <script src="<?php echo site_url() ?>system/resources/js/form.builder.js"></script>