ninja_forms_field_calc_edit
Function that outputs the edit options for our calculation field.
Description
Parameters (2)
- 0. $field_id
- The field id.
- 1. $data
- The data.
Usage
if ( !function_exists( 'ninja_forms_field_calc_edit' ) ) { require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/fields/calc.php'; } // The field id. $field_id = null; // The data. $data = null; // NOTICE! Understand what this does before running. $result = ninja_forms_field_calc_edit($field_id, $data);
Defined (1)
The function is defined in the following location(s).
- /deprecated/includes/fields/calc.php
- function ninja_forms_field_calc_edit( $field_id, $data ) {
- $calc_name = isset ( $data['calc_name'] ) ? $data['calc_name'] : 'calc_name';
- $default_value = isset ( $data['default_value'] ) ? $data['default_value'] : '';
- $calc_payment = isset ( $data['calc_payment'] ) ? $data['calc_payment'] : '';
- $calc_autho = isset ( $data['calc_auto'] ) ? $data['calc_auto'] : 0;
- // Output calculation display type
- $options = array(
- array( 'name' => __( '- None', 'ninja-forms' ), 'value' => 'hidden' ),
- array( 'name' => __( 'Textbox', 'ninja-forms' ), 'value' => 'text'),
- array( 'name' => __( 'HTML', 'ninja-forms' ), 'value' => 'html'),
- );
- $calc_display_type = isset ( $data['calc_display_type'] ) ? $data['calc_display_type'] : 'text';
- 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');
- // If the calc_display_type is set to text, then we have several options to output.
- // Set the output to hidden for these options if the calc_display_type is not set to text.
- if ( $calc_display_type != 'text' ) {
- $class = 'hidden';
- } else {
- $class = '';
- }
- echo '<div id="ninja_forms_field_'.$field_id.'_calc_text_display" class="'.$class.'">';
- // Output a label input textbox.
- $label = isset ( $data['label'] ) ? stripslashes( $data['label'] ) : __( 'Calculation', 'ninja-forms' );
- ninja_forms_edit_field_el_output($field_id, 'text', __( 'Label', 'ninja-forms' ), 'label', $label, 'wide', '', 'widefat');
- // Output a label position select box.
- if ( isset ( $data['label_pos'] ) ) {
- $label_pos = $data['label_pos'];
- } else {
- $label_pos = '';
- }
- $options = array(
- array('name' => __( 'Left of Element', 'ninja-forms' ), 'value' => 'left'),
- array('name' => __( 'Above Element', 'ninja-forms' ), 'value' => 'above'),
- array('name' => __( 'Below Element', 'ninja-forms' ), 'value' => 'below'),
- array('name' => __( 'Right of Element', 'ninja-forms' ), 'value' => 'right'),
- );
- ninja_forms_edit_field_el_output($field_id, 'select', __( 'Label Position', 'ninja-forms' ), 'label_pos', $label_pos, 'wide', $options, 'widefat');
- // Output a disabled option checkbox.
- if( isset ( $data['calc_display_text_disabled'] ) ) {
- $calc_display_text_disabled = $data['calc_display_text_disabled'];
- } else {
- $calc_display_text_disabled = 1;
- }
- ninja_forms_edit_field_el_output($field_id, 'checkbox', __( 'Disable input?', 'ninja-forms' ), 'calc_display_text_disabled', $calc_display_text_disabled, 'wide', '', '');
- echo '</div>';
- // Set the output to hidden for the HTML RTE if the calc_display_type is not set to HTML.
- if ( $calc_display_type != 'html' ) {
- $class = 'hidden';
- } else {
- $class = '';
- }
- // Output our RTE. This is the only extra setting needed if the calc_display_type is set to HTML.
- if ( isset ( $data['calc_display_html'] ) ) {
- $calc_display_html = $data['calc_display_html'];
- } else {
- $calc_display_html = '[ninja_forms_calc]';
- }
- echo '<div id="ninja_forms_field_'.$field_id.'_calc_html_display" class="'.$class.'">';
- 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' ) );
- echo '</div>';
- if ( isset ( $data['calc_method'] ) ) {
- $calc_method = $data['calc_method'];
- } else {
- $calc_method = 'auto';
- }
- switch ( $calc_method ) {
- case 'auto':
- $eq_class = 'hidden';
- $field_class = 'hidden';
- break;
- case 'fields':
- $eq_class = 'hidden';
- $field_class = '';
- break;
- case 'eq':
- $eq_class = '';
- $field_class = 'hidden';
- break;
- }
- if ( isset ( $data['calc_eq'] ) ) {
- $calc_eq = $data['calc_eq'];
- } else {
- $calc_eq = '';
- }
- if ( isset ( $data['calc'] ) AND $data['calc'] != '' ) {
- $calc = $data['calc'];
- } else {
- $calc = array();
- }
- $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>';
- $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>';
- $desc .= '<p>' .__( 'Please use these operators: + - * /. This is an advanced feature. Watch out for things like division by 0.', 'ninja-forms' ).'</p>';
- $options = array(
- array( 'name' => __( 'Automatically Total Calculation Values', 'ninja-forms' ), 'value' => 'auto' ),
- array( 'name' => __( 'Specify Operations And Fields (Advanced)', 'ninja-forms' ), 'value' => 'fields' ),
- array( 'name' => __( 'Use An Equation (Advanced)', 'ninja-forms' ), 'value' => 'eq' ),
- );
- ninja_forms_edit_field_el_output($field_id, 'select', __( 'Calculation Method', 'ninja-forms' ), 'calc_method', $calc_method, 'wide', $options, 'widefat ninja-forms-calc-method');
- ?>
- <div class="ninja-forms-calculations <?php echo $field_class;?>">
- <div class="label">
- <?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>
- <span class="spinner" style="float:left;"></span>
- </div>
- <input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[calc]" value="">
- <div id="ninja_forms_field_<?php echo $field_id;?>_calc" class="" name="">
- <?php
- $x = 0;
- foreach ( $calc as $c ) {
- ninja_forms_output_field_calc_row( $field_id, $c, $x );
- $x++;
- }
- ?>
- </div>
- </div>
- <div class="ninja-forms-eq <?php echo $eq_class;?>">
- <?php
- ninja_forms_edit_field_el_output($field_id, 'textarea', __( 'Advanced Equation', 'ninja-forms' ), 'calc_eq', $calc_eq, 'wide', '', 'widefat', $desc);
- ?>
- </div>
- <hr>
- <?php