ninja_forms_field_calc_edit

Function that outputs the edit options for our calculation field.

Description

ninja_forms_field_calc_edit( $field_id, $data ); 

Parameters (2)

0. $field_id
The field id.
1. $data
The data.

Usage

  1. if ( !function_exists( 'ninja_forms_field_calc_edit' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/fields/calc.php'; 
  3.  
  4. // The field id. 
  5. $field_id = null; 
  6.  
  7. // The data. 
  8. $data = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ninja_forms_field_calc_edit($field_id, $data); 
  12.  

Defined (1)

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

/deprecated/includes/fields/calc.php  
  1. function ninja_forms_field_calc_edit( $field_id, $data ) { 
  2. $calc_name = isset ( $data['calc_name'] ) ? $data['calc_name'] : 'calc_name'; 
  3. $default_value = isset ( $data['default_value'] ) ? $data['default_value'] : '';  
  4. $calc_payment = isset ( $data['calc_payment'] ) ? $data['calc_payment'] : ''; 
  5. $calc_autho = isset ( $data['calc_auto'] ) ? $data['calc_auto'] : 0; 
  6.  
  7. // Output calculation display type 
  8. $options = array( 
  9. array( 'name' => __( '- None', 'ninja-forms' ), 'value' => 'hidden' ),  
  10. array( 'name' => __( 'Textbox', 'ninja-forms' ), 'value' => 'text'),  
  11. array( 'name' => __( 'HTML', 'ninja-forms' ), 'value' => 'html'),  
  12. ); 
  13.  
  14. $calc_display_type = isset ( $data['calc_display_type'] ) ? $data['calc_display_type'] : 'text'; 
  15.  
  16. ninja_forms_edit_field_el_output($field_id, 'select', __( 'Output calculation as', 'ninja-forms' ), 'calc_display_type', $calc_display_type, 'wide', $options, 'widefat ninja-forms-calc-display'); 
  17.  
  18. // If the calc_display_type is set to text, then we have several options to output. 
  19. // Set the output to hidden for these options if the calc_display_type is not set to text. 
  20. if ( $calc_display_type != 'text' ) { 
  21. $class = 'hidden'; 
  22. } else { 
  23. $class = ''; 
  24. echo '<div id="ninja_forms_field_'.$field_id.'_calc_text_display" class="'.$class.'">'; 
  25. // Output a label input textbox. 
  26. $label = isset ( $data['label'] ) ? stripslashes( $data['label'] ) : __( 'Calculation', 'ninja-forms' ); 
  27.  
  28. ninja_forms_edit_field_el_output($field_id, 'text', __( 'Label', 'ninja-forms' ), 'label', $label, 'wide', '', 'widefat'); 
  29.  
  30. // Output a label position select box. 
  31. if ( isset ( $data['label_pos'] ) ) { 
  32. $label_pos = $data['label_pos']; 
  33. } else { 
  34. $label_pos = ''; 
  35. $options = array( 
  36. array('name' => __( 'Left of Element', 'ninja-forms' ), 'value' => 'left'),  
  37. array('name' => __( 'Above Element', 'ninja-forms' ), 'value' => 'above'),  
  38. array('name' => __( 'Below Element', 'ninja-forms' ), 'value' => 'below'),  
  39. array('name' => __( 'Right of Element', 'ninja-forms' ), 'value' => 'right'),  
  40. ); 
  41. ninja_forms_edit_field_el_output($field_id, 'select', __( 'Label Position', 'ninja-forms' ), 'label_pos', $label_pos, 'wide', $options, 'widefat'); 
  42.  
  43. // Output a disabled option checkbox. 
  44. if( isset ( $data['calc_display_text_disabled'] ) ) { 
  45. $calc_display_text_disabled = $data['calc_display_text_disabled']; 
  46. } else { 
  47. $calc_display_text_disabled = 1; 
  48. ninja_forms_edit_field_el_output($field_id, 'checkbox', __( 'Disable input?', 'ninja-forms' ), 'calc_display_text_disabled', $calc_display_text_disabled, 'wide', '', ''); 
  49. echo '</div>'; 
  50.  
  51. // Set the output to hidden for the HTML RTE if the calc_display_type is not set to HTML. 
  52. if ( $calc_display_type != 'html' ) { 
  53. $class = 'hidden'; 
  54. } else { 
  55. $class = ''; 
  56. // Output our RTE. This is the only extra setting needed if the calc_display_type is set to HTML. 
  57. if ( isset ( $data['calc_display_html'] ) ) { 
  58. $calc_display_html = $data['calc_display_html']; 
  59. } else { 
  60. $calc_display_html = '[ninja_forms_calc]'; 
  61. echo '<div id="ninja_forms_field_'.$field_id.'_calc_html_display" class="'.$class.'">'; 
  62. ninja_forms_edit_field_el_output($field_id, 'rte', '', 'calc_display_html', $calc_display_html, '', '', '', __( 'Use the following shortcode to insert the final calculation: [ninja_forms_calc]', 'ninja-forms' ) ); 
  63. echo '</div>'; 
  64.  
  65. if ( isset ( $data['calc_method'] ) ) { 
  66. $calc_method = $data['calc_method']; 
  67. } else { 
  68. $calc_method = 'auto'; 
  69.  
  70. switch ( $calc_method ) { 
  71. case 'auto': 
  72. $eq_class = 'hidden'; 
  73. $field_class = 'hidden'; 
  74. break; 
  75. case 'fields': 
  76. $eq_class = 'hidden'; 
  77. $field_class = ''; 
  78. break; 
  79. case 'eq': 
  80. $eq_class = ''; 
  81. $field_class = 'hidden'; 
  82. break; 
  83.  
  84.  
  85. if ( isset ( $data['calc_eq'] ) ) { 
  86. $calc_eq = $data['calc_eq']; 
  87. } else { 
  88. $calc_eq = ''; 
  89.  
  90. if ( isset ( $data['calc'] ) AND $data['calc'] != '' ) { 
  91. $calc = $data['calc']; 
  92. } else { 
  93. $calc = array(); 
  94.  
  95. $desc = '<p>' . sprintf( __( 'You can enter calculation equations here using field_x where x is the ID of the field you want to use. For example, %sfield_53 + field_28 + field_65%s.', 'field_ should NOT be translated.', 'ninja-forms' ), '<strong>', '</strong>' ) . '</p>'; 
  96. $desc .= '<p>' . sprintf( __( 'Complex equations can be created by adding parentheses: %s( field_45 * field_2 ) / 2%s.', 'field_ should NOT be translated.', 'ninja-forms' ), '<strong>', '</strong>' ) . '</p>'; 
  97. $desc .= '<p>' .__( 'Please use these operators: + - * /. This is an advanced feature. Watch out for things like division by 0.', 'ninja-forms' ).'</p>'; 
  98. $options = array( 
  99. array( 'name' => __( 'Automatically Total Calculation Values', 'ninja-forms' ), 'value' => 'auto' ),  
  100. array( 'name' => __( 'Specify Operations And Fields (Advanced)', 'ninja-forms' ), 'value' => 'fields' ),  
  101. array( 'name' => __( 'Use An Equation (Advanced)', 'ninja-forms' ), 'value' => 'eq' ),  
  102. ); 
  103. ninja_forms_edit_field_el_output($field_id, 'select', __( 'Calculation Method', 'ninja-forms' ), 'calc_method', $calc_method, 'wide', $options, 'widefat ninja-forms-calc-method'); 
  104.  
  105. ?> 
  106.  
  107. <div class="ninja-forms-calculations <?php echo $field_class;?>"> 
  108. <div class="label"> 
  109. <?php _e( 'Field Operations', 'ninja-forms' );?> - <a href="#" name="" id="ninja_forms_field_<?php echo $field_id;?>_add_calc" class="ninja-forms-field-add-calc" rel="<?php echo $field_id;?>"><?php _e( 'Add Operation', 'ninja-forms' );?></a> 
  110.  
  111. <span class="spinner" style="float:left;"></span> 
  112. </div> 
  113.  
  114. <input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[calc]" value=""> 
  115. <div id="ninja_forms_field_<?php echo $field_id;?>_calc" class="" name=""> 
  116. <?php 
  117. $x = 0; 
  118. foreach ( $calc as $c ) { 
  119. ninja_forms_output_field_calc_row( $field_id, $c, $x ); 
  120. $x++; 
  121. ?> 
  122. </div> 
  123. </div> 
  124. <div class="ninja-forms-eq <?php echo $eq_class;?>"> 
  125. <?php 
  126. ninja_forms_edit_field_el_output($field_id, 'textarea', __( 'Advanced Equation', 'ninja-forms' ), 'calc_eq', $calc_eq, 'wide', '', 'widefat', $desc); 
  127. ?> 
  128. </div> 
  129. <hr> 
  130. <?php