field_wrapper_template

The Caldera Forms field wrapper template function.

Description

Parameters (10)

0. $id — Optional. (string) => '{{id}}'
The id.
1. $label — Optional. (string) => '{{label}}'
The label.
2. $slug — Optional. (string) => '{{slug}}'
The slug.
3. $caption — Optional. (string) => '{{caption}}'
The caption.
4. $hide_label — Optional. (string) => '{{hide_label}}'
The hide label.
5. $required — Optional. (string) => '{{required}}'
The required.
6. $entry_list — Optional. (string) => '{{entry_list}}'
The entry list.
7. $type — Optional. (constant) => null
The type.
8. $config_str — Optional. (string) => '{{json config}}'
The config str.
9. $conditions_str — Optional. (string) => '{"type" : ""}'
The conditions str.

Usage

  1. if ( !function_exists( 'field_wrapper_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'caldera-forms/ui/edit.php'; 
  3.  
  4. // The id. 
  5. $id = '{{id}}'; 
  6.  
  7. // The label. 
  8. $label = '{{label}}'; 
  9.  
  10. // The slug. 
  11. $slug = '{{slug}}'; 
  12.  
  13. // The caption. 
  14. $caption = '{{caption}}'; 
  15.  
  16. // The hide label. 
  17. $hide_label = '{{hide_label}}'; 
  18.  
  19. // The required. 
  20. $required = '{{required}}'; 
  21.  
  22. // The entry list. 
  23. $entry_list = '{{entry_list}}'; 
  24.  
  25. // The type. 
  26. $type = null; 
  27.  
  28. // The config str. 
  29. $config_str = '{{json config}}'; 
  30.  
  31. // The conditions str. 
  32. $conditions_str = '{"type" : ""}'; 
  33.  
  34. // NOTICE! Understand what this does before running. 
  35. $result = field_wrapper_template($id, $label, $slug, $caption, $hide_label, $required, $entry_list, $type, $config_str, $conditions_str); 
  36.  

Defined (1)

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

/ui/edit.php  
  1. function field_wrapper_template($id = '{{id}}', $label = '{{label}}', $slug = '{{slug}}', $caption = '{{caption}}', $hide_label = '{{hide_label}}', $required = '{{required}}', $entry_list = '{{entry_list}}', $type = null, $config_str = '{{json config}}', $conditions_str = '{"type" : ""}') { 
  2.  
  3. if(is_array($config_str)) { 
  4. $config = $config_str; 
  5. $config_str = json_encode( $config_str ); 
  6.  
  7. }else{ 
  8. $config = json_decode($config_str, true); 
  9.  
  10.  
  11. $condition_type = ''; 
  12. if(!empty($conditions_str)) { 
  13. $conditions = json_decode($conditions_str, true); 
  14. if(!empty($conditions['type'])) { 
  15. $condition_type = $conditions['type']; 
  16. if(!empty($conditions['group'])) { 
  17. $groups = array(); 
  18. foreach ($conditions['group'] as $groupid => $group) { 
  19. $group_tmp = array( 
  20. 'id' => $groupid,  
  21. 'type' => 'fields',  
  22. 'lines' => array() 
  23. ); 
  24. if(!empty($group)) { 
  25. foreach($group as $line_id => $line) { 
  26. $group_line = $line; 
  27. $group_line['id'] = $line_id; 
  28. $group_tmp['lines'][] = $group_line; 
  29. $groups[] = $group_tmp; 
  30. $conditions['group'] = $groups; 
  31. $conditions_str = json_encode($conditions); 
  32. }  
  33. //dump($conditions, 0); 
  34. ?> 
  35. <div class="caldera-editor-field-config-wrapper caldera-editor-config-wrapper ajax-trigger"  
  36.  
  37. data-request="setup_field_type"  
  38. data-event="field.drop" 
  39. data-load-class="none" 
  40. data-modal="field_setup" 
  41. data-modal-title="<?php echo esc_html__( 'Fields', 'caldera-forms' ); ?>" 
  42. data-template="#form-fields-selector-tmpl" 
  43. data-modal-width="700" 
  44. data-modal-height="680" 
  45.  
  46. id="<?php echo $id; ?>" style="display:none;"> 
  47.  
  48.  
  49. <h3 class="caldera-editor-field-title"><?php echo $label; ?> </h3>  
  50. <input type="hidden" class="field-config" name="config[fields][<?php echo $id; ?>][ID]" value="<?php echo $id; ?>"> 
  51. <div id="<?php echo $id; ?>_settings_pane" class="wrapper-instance-pane"> 
  52. <div class="caldera-config-group"> 
  53. <label for="<?php echo $id; ?>_type"><?php echo esc_html__( 'Field Type', 'caldera-forms' ); ?></label> 
  54. <div class="caldera-config-field"> 
  55. <select class="block-input caldera-select-field-type" data-field="<?php echo $id; ?>" id="<?php echo $id; ?>_type" name="config[fields][<?php echo $id; ?>][type]" data-type="<?php echo $type; ?>">  
  56. <?php 
  57. echo build_field_types($type); 
  58. ?> 
  59. </select> 
  60. </div> 
  61. </div> 
  62. <div class="caldera-config-group"> 
  63. <label for="<?php echo $id; ?>_fid"><?php echo esc_html__( 'ID', 'caldera-forms' ); ?></label> 
  64. <div class="caldera-config-field"> 
  65. <input type="text" class="block-input field-id" id="<?php echo $id; ?>_fid" value="<?php echo $id; ?>" readonly="readonly"> 
  66. </div> 
  67. </div> 
  68.  
  69.  
  70. <div class="caldera-config-group"> 
  71. <label for="<?php echo $id; ?>_lable"><?php echo esc_html__( 'Name', 'caldera-forms' ); ?></label> 
  72. <div class="caldera-config-field"> 
  73. <input type="text" class="block-input field-config field-label required" id="<?php echo $id; ?>_lable" name="config[fields][<?php echo $id; ?>][label]" value="<?php echo sanitize_text_field( $label ); ?>"> 
  74. </div> 
  75. </div> 
  76.  
  77. <div class="caldera-config-group hide-label-field"> 
  78. <label for="<?php echo $id; ?>_hide_label"><?php echo esc_html__( 'Hide Label', 'caldera-forms' ); ?></label> 
  79. <div class="caldera-config-field"> 
  80. <input type="checkbox" class="field-config field-checkbox" id="<?php echo $id; ?>_hide_label" name="config[fields][<?php echo $id; ?>][hide_label]" value="1" <?php if($hide_label === 1) { echo 'checked="checked"'; }else{?>{{#if hide_label}}checked="checked"{{/if}}<?php } ?>> 
  81. </div> 
  82. </div> 
  83.  
  84. <div class="caldera-config-group"> 
  85. <label for="<?php echo $id; ?>_slug"><?php echo esc_html__( 'Slug', 'caldera-forms' ); ?></label> 
  86. <div class="caldera-config-field"> 
  87. <input type="text" class="block-input field-config field-slug required" id="<?php echo $id; ?>_slug" name="config[fields][<?php echo $id; ?>][slug]" value="<?php echo $slug; ?>"> 
  88. </div> 
  89. </div> 
  90. <div class="caldera-config-group"> 
  91. <label for="<?php echo $id; ?>_fcond"><?php echo esc_html__( 'Condition', 'caldera-forms' ); ?></label> 
  92. <div class="caldera-config-field"> 
  93. <select id="field-condition-type-<?php echo $id; ?>" name="config[fields][<?php echo $id; ?>][conditions][type]" data-id="<?php echo $id; ?>" class="caldera-conditionals-usetype block-input"> 
  94. <option></option> 
  95. <optgroup class="cf-conditional-selector"> 
  96. <?php if( !in_array( $condition_type, array( 'show', 'hide', 'disable' ) ) ) { ?><option value="<?php echo $condition_type; ?>" selected="selected"><?php echo esc_html__( 'Disable', 'caldera-forms' ); ?></option><?php } ?></optgroup> 
  97. </optgroup> 
  98. </select> 
  99. </div> 
  100. </div>  
  101. <div class="caldera-config-group required-field"> 
  102. <label for="<?php echo $id; ?>_required"><?php echo esc_html__( 'Required', 'caldera-forms' ); ?></label> 
  103. <div class="caldera-config-field"> 
  104. <input type="checkbox" class="field-config field-required field-checkbox" id="<?php echo $id; ?>_required" name="config[fields][<?php echo $id; ?>][required]" value="1" <?php if($required === 1) { echo 'checked="checked"'; }else{?>{{#if required}}checked="checked"{{/if}}<?php } ?>> 
  105. </div> 
  106. </div> 
  107.  
  108. <div class="caldera-config-group caption-field"> 
  109. <label for="<?php echo $id; ?>_caption"><?php echo esc_html__( 'Description', 'caldera-forms' ); ?></label> 
  110. <div class="caldera-config-field"> 
  111. <input type="text" class="block-input field-config" id="<?php echo $id; ?>_caption" name="config[fields][<?php echo $id; ?>][caption]" value="<?php echo esc_html( $caption ); ?>"> 
  112. </div> 
  113. </div> 
  114.  
  115. <div class="caldera-config-group entrylist-field"> 
  116. <label for="<?php echo $id; ?>_entry_list"><?php echo esc_html__( 'Show in Entry List', 'caldera-forms' ); ?></label> 
  117. <div class="caldera-config-field"> 
  118. <input type="checkbox" class="field-config field-checkbox" id="<?php echo $id; ?>_entry_list" name="config[fields][<?php echo $id; ?>][entry_list]" value="1" <?php if($entry_list === 1) { echo 'checked="checked"'; }else{?>{{#if entry_list}}checked="checked"{{/if}}<?php } ?>> 
  119. </div> 
  120. </div> 
  121. <div class="caldera-config-field-setup"> 
  122. </div> 
  123. <input type="hidden" class="field_config_string block-input" value="<?php echo htmlentities( $config_str ); ?>"> 
  124. <input type="hidden" class="field_conditions_config_string block-input ajax-trigger" data-event="none" data-autoload="true" data-request="build_conditions_config" data-template="#conditional-group-tmpl" data-id="<?php echo $id; ?>" data-target="#<?php echo $id; ?>_conditional_wrap" data-type="fields" data-callback="rebuild_field_binding" value="<?php echo htmlentities( $conditions_str ); ?>"> 
  125. <br> 
  126. <button class="button delete-field block-button" data-confirm="<?php echo esc_html__( 'Are you sure you want to remove this field?. \'Cancel\' to stop. \'OK\' to delete', 'caldera-forms' ); ?>" type="button"><?php echo esc_html__( 'Delete Field', 'caldera-forms' ); ?></button> 
  127. </div> 
  128.  
  129. </div> 
  130. <?php