PodsBuilderModuleForm

The Pods - Custom Content Types and Fields PodsBuilderModuleForm class.

Defined (1)

The class is defined in the following location(s).

/components/Builder/modules/form/PodsBuilderModuleForm.php  
  1. class PodsBuilderModuleForm extends LayoutModule { 
  2.  
  3. var $_name = ''; 
  4. var $_var = 'pods-builder-form'; 
  5. var $_description = ''; 
  6. var $_editor_width = 500; 
  7. var $_can_remove_wrappers = true; 
  8.  
  9. /** 
  10. * Register the Module 
  11. */ 
  12. public function PodsBuilderModuleForm () { 
  13. $this->_name = __( 'Pods - Form', 'pods' ); 
  14. $this->_description = __( 'Display a form for creating and editing Pod items', 'pods' ); 
  15. $this->module_path = dirname( __FILE__ ); 
  16.  
  17. $this->LayoutModule(); 
  18.  
  19. /** 
  20. * Set default variables 
  21. * @param $defaults 
  22. * @return mixed 
  23. */ 
  24. function _get_defaults ( $defaults ) { 
  25. $new_defaults = array( 
  26. 'pod_type' => '',  
  27. 'slug' => '',  
  28. 'fields' => '',  
  29. 'label' => __( 'Submit', 'pods' ),  
  30. 'thank_you' => '',  
  31. 'sidebar' => 'none' 
  32. ); 
  33.  
  34. return ITUtility::merge_defaults( $new_defaults, $defaults ); 
  35.  
  36. /** 
  37. * Output something before the table form 
  38. * @param object $form Form class 
  39. * @param bool $results 
  40. */ 
  41. function _before_table_edit ( $form, $results = true ) { 
  42. ?> 
  43. <p><?php echo $this->_description; ?></p> 
  44. <?php 
  45.  
  46. /** 
  47. * Output something at the start of the table form 
  48. * @param object $form Form class 
  49. * @param bool $results 
  50. */ 
  51. function _start_table_edit ( $form, $results = true ) { 
  52. $api = pods_api(); 
  53. $all_pods = $api->load_pods( array( 'names' => true ) ); 
  54.  
  55. $pod_types = array(); 
  56.  
  57. foreach ( $all_pods as $pod_name => $pod_label ) { 
  58. $pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; 
  59. ?> 
  60. <tr> 
  61. <td valign="top"> 
  62. <label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label> 
  63. </td> 
  64. <td> 
  65. <?php 
  66. if ( 0 < count( $all_pods ) ) 
  67. $form->add_drop_down( 'pod_type', $pod_types ); 
  68. else 
  69. echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; 
  70. ?> 
  71. </td> 
  72. </tr> 
  73. <tr> 
  74. <td valign="top"> 
  75. <label for="slug"><?php _e( 'Slug or ID', 'pods' ); ?></label> 
  76. </td> 
  77. <td> 
  78. <?php $form->add_text_box( 'slug' ); ?> 
  79. </td> 
  80. </tr> 
  81. <tr> 
  82. <td valign="top"> 
  83. <label for="fields"><?php _e( 'Fields (comma-separated)', 'pods' ); ?></label> 
  84. </td> 
  85. <td> 
  86. <?php $form->add_text_box( 'fields' ); ?> 
  87. </td> 
  88. </tr> 
  89. <tr> 
  90. <td valign="top"> 
  91. <label for="label"><?php _e( 'Submit Label', 'pods' ); ?></label> 
  92. </td> 
  93. <td> 
  94. <?php $form->add_text_box( 'label' ); ?> 
  95. </td> 
  96. </tr> 
  97. <tr> 
  98. <td valign="top"> 
  99. <label for="thank_you"><?php _e( 'Thank You URL upon submission', 'pods' ); ?></label> 
  100. </td> 
  101. <td> 
  102. <?php $form->add_text_box( 'thank_you' ); ?> 
  103. </td> 
  104. </tr> 
  105. <?php 
  106.  
  107. /** 
  108. * Module Output 
  109. */ 
  110. function _render ( $fields ) { 
  111. $args = array( 
  112. 'name' => trim( pods_var_raw( 'pod_type', $fields[ 'data' ], '' ) ),  
  113. 'slug' => trim( pods_var_raw( 'slug', $fields[ 'data' ], '' ) ),  
  114. 'fields' => trim( pods_var_raw( 'fields', $fields[ 'data' ], '' ) ),  
  115. 'label' => trim( pods_var_raw( 'label', $fields[ 'data' ], __( 'Submit', 'pods' ), null, true ) ),  
  116. 'thank_you' => trim( pods_var_raw( 'thank_you', $fields[ 'data' ], '' ) ),  
  117. 'form' => 1 
  118. ); 
  119.  
  120. if ( 0 < strlen( $args[ 'name' ] ) ) 
  121. echo pods_shortcode( $args, ( isset( $content ) ? $content : null ) ); 
  122.