ninja_forms_output_field_calc_row

Function to output specific calculation options for a given field.

Description

ninja_forms_output_field_calc_row( (int) $field_id, (array) $c = array(), (int) $x = 0 ); 

Parameters (3)

0. $field_id (int)
- ID of the field being edited.
1. $c — Optional. (array) => array()
- Array containing the data.
2. $x — Optional. (int)
- Index for this row of the calc array.

Usage

  1. if ( !function_exists( 'ninja_forms_output_field_calc_row' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/fields/calc.php'; 
  3.  
  4. // - ID of the field being edited. 
  5. $field_id = -1; 
  6.  
  7. // - Array containing the data. 
  8. $c = array(); 
  9.  
  10. // - Index for this row of the calc array. 
  11. $x = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = ninja_forms_output_field_calc_row($field_id, $c, $x); 
  15.  

Defined (1)

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

/deprecated/includes/fields/calc.php  
  1. function ninja_forms_output_field_calc_row( $field_id, $c = array(), $x = 0 ) { 
  2. global $ninja_forms_fields; 
  3. $field_row = ninja_forms_get_field_by_id( $field_id ); 
  4. $field_type = $field_row['type']; 
  5. $form_id = $field_row['form_id']; 
  6.  
  7. if ( isset ( $c['field'] ) ) { 
  8. $calc_field = $c['field']; 
  9. } else { 
  10. $calc_field = ''; 
  11.  
  12. if ( isset ( $c['op'] ) ) { 
  13. $op = $c['op']; 
  14. } else { 
  15. $op = ''; 
  16.  
  17. ?> 
  18. <div id="ninja_forms_field_<?php echo $field_id;?>_calc_row_<?php echo $x;?>" class="ninja-forms-calc-row" rel="<?php echo $x;?>"> 
  19. <a href="#" id="ninja_forms_field_<?php echo $field_id;?>_remove_calc" name="<?php echo $x;?>" rel="<?php echo $field_id;?>" class="ninja-forms-field-remove-calc">X</a> 
  20.  
  21. <select name="ninja_forms_field_<?php echo $field_id;?>[calc][<?php echo $x;?>][op]"> 
  22. <option value="add" <?php selected( $op, 'add' );?>>+</option> 
  23. <option value="subtract" <?php selected( $op, 'subtract' );?>>-</option> 
  24. <option value="multiply" <?php selected( $op, 'multiply' );?>>*</option> 
  25. <option value="divide" <?php selected( $op, 'divide' );?>>/</option> 
  26. </select> 
  27.  
  28. <select name="ninja_forms_field_<?php echo $field_id;?>[calc][<?php echo $x;?>][field]" class="ninja-forms-calc-select"> 
  29. <option value=""><?php _e( '- Select a Field', 'ninja-forms' );?></option> 
  30. <?php 
  31. // Loop through our fields and output all of our calculation fields. 
  32. $fields = ninja_forms_get_fields_by_form_id( $form_id ); 
  33. foreach ( $fields as $field ) { 
  34. if ( isset ( $field['data']['label'] ) ) { 
  35. $label = $field['data']['label']; 
  36. } else { 
  37. $label = ''; 
  38. if ( strlen ( $label ) > 15 ) { 
  39. $label = substr ( $label, 0, 15 ); 
  40. $label .= '...'; 
  41. $process_field = $ninja_forms_fields[$field['type']]['process_field']; 
  42. if ( $field['id'] != $field_id AND $process_field ) { 
  43. ?> 
  44. <option value="<?php echo $field['id'];?>" <?php selected( $calc_field, $field['id'] );?>><?php echo $field['id'];?> - <?php echo $label;?></option> 
  45. <?php 
  46. ?> 
  47. </select> 
  48. </div> 
  49. <?php