Commit 3ac377b9 authored by Kevin Stover's avatar Kevin Stover

Merge branch 'release/v2.2.49'

parents e9a77c5b 1ded91d2
...@@ -100,6 +100,7 @@ function ninja_forms_export_subs_to_csv( $sub_ids = '', $return = false ){ ...@@ -100,6 +100,7 @@ function ninja_forms_export_subs_to_csv( $sub_ids = '', $return = false ){
header("Content-Disposition: attachment; filename=".$filename); header("Content-Disposition: attachment; filename=".$filename);
header("Pragma: no-cache"); header("Pragma: no-cache");
header("Expires: 0"); header("Expires: 0");
echo "\xEF\xBB\xBF"; // Byte Order Mark
echo str_putcsv($array); echo str_putcsv($array);
die(); die();
......
...@@ -240,6 +240,15 @@ function ninja_forms_calc_after_import_form( $form ){ ...@@ -240,6 +240,15 @@ function ninja_forms_calc_after_import_form( $form ){
} }
} }
} }
if ( isset ( $field_rows[$y]['data']['calc_eq'] ) AND $field_rows[$y]['data']['calc_eq'] != '' ) {
$calc_eq = $field_rows[$y]['data']['calc_eq'];
foreach( $form['field'] as $inserted_field ){
$calc_eq = str_replace( 'field_'.$inserted_field['old_id'], 'field_'.$inserted_field['id'], $calc_eq );
}
$field_rows[$y]['data']['calc_eq'] = $calc_eq;
}
$field_rows[$y]['data'] = serialize( $field_rows[$y]['data'] ); $field_rows[$y]['data'] = serialize( $field_rows[$y]['data'] );
$args = array( $args = array(
'update_array' => array( 'update_array' => array(
...@@ -251,6 +260,64 @@ function ninja_forms_calc_after_import_form( $form ){ ...@@ -251,6 +260,64 @@ function ninja_forms_calc_after_import_form( $form ){
); );
ninja_forms_update_field($args); ninja_forms_update_field($args);
} }
if ( isset ( $form['data']['success_msg'] ) AND $form['data']['success_msg'] != '' ) {
$success_msg = $form['data']['success_msg'];
foreach( $form['field'] as $inserted_field ){
$success_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $success_msg );
}
$form['data']['success_msg'] = $success_msg;
}
if ( isset ( $form['data']['user_email_msg'] ) AND $form['data']['user_email_msg'] != '' ) {
$user_email_msg = $form['data']['user_email_msg'];
foreach( $form['field'] as $inserted_field ){
$user_email_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $user_email_msg );
}
$form['data']['user_email_msg'] = $user_email_msg;
}
if ( isset ( $form['data']['admin_email_msg'] ) AND $form['data']['admin_email_msg'] != '' ) {
$admin_email_msg = $form['data']['admin_email_msg'];
foreach( $form['field'] as $inserted_field ){
$admin_email_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $admin_email_msg );
}
$form['data']['admin_email_msg'] = $admin_email_msg;
}
if ( isset ( $form['data']['mp_confirm_msg'] ) AND $form['data']['mp_confirm_msg'] != '' ) {
$mp_confirm_msg = $form['data']['mp_confirm_msg'];
foreach( $form['field'] as $inserted_field ){
$mp_confirm_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $mp_confirm_msg );
}
$form['data']['mp_confirm_msg'] = $mp_confirm_msg;
}
if ( isset ( $form['data']['save_msg'] ) AND $form['data']['save_msg'] != '' ) {
$save_msg = $form['data']['save_msg'];
foreach( $form['field'] as $inserted_field ){
$save_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $save_msg );
}
$form['data']['save_msg'] = $save_msg;
}
if ( isset ( $form['data']['save_email_msg'] ) AND $form['data']['save_email_msg'] != '' ) {
$save_email_msg = $form['data']['save_email_msg'];
foreach( $form['field'] as $inserted_field ){
$save_email_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $save_email_msg );
}
$form['data']['save_email_msg'] = $save_email_msg;
}
$args = array(
'update_array' => array(
'data' => serialize( $form['data'] ),
),
'where' => array(
'id' => $form['id'],
),
);
ninja_forms_update_form($args);
} }
} }
} }
\ No newline at end of file
...@@ -346,6 +346,7 @@ function ninja_forms_tab_view_subs(){ ...@@ -346,6 +346,7 @@ function ninja_forms_tab_view_subs(){
add_filter('ninja_forms_field', 'ninja_forms_edit_sub_default_value', 15, 2); add_filter('ninja_forms_field', 'ninja_forms_edit_sub_default_value', 15, 2);
add_filter('ninja_forms_field', 'ninja_forms_edit_sub_hide_fields', 99, 2); add_filter('ninja_forms_field', 'ninja_forms_edit_sub_hide_fields', 99, 2);
add_filter( 'ninja_forms_display_form_form_data', 'ninja_forms_edit_sub_remove_ajax' );
remove_action('ninja_forms_display_before_fields', 'ninja_forms_display_req_items'); remove_action('ninja_forms_display_before_fields', 'ninja_forms_display_req_items');
remove_action('ninja_forms_display_open_form_tag', 'ninja_forms_display_open_form_tag'); remove_action('ninja_forms_display_open_form_tag', 'ninja_forms_display_open_form_tag');
remove_action('ninja_forms_display_close_form_tag', 'ninja_forms_display_close_form_tag'); remove_action('ninja_forms_display_close_form_tag', 'ninja_forms_display_close_form_tag');
...@@ -430,9 +431,17 @@ function ninja_forms_tab_view_subs(){ ...@@ -430,9 +431,17 @@ function ninja_forms_tab_view_subs(){
if(isset($_POST['_ninja_forms_edit_sub']) AND $_POST['_ninja_forms_edit_sub'] == 1){ if(isset($_POST['_ninja_forms_edit_sub']) AND $_POST['_ninja_forms_edit_sub'] == 1){
add_action( 'init', 'ninja_forms_setup_processing_class', 5 ); add_action( 'init', 'ninja_forms_setup_processing_class', 5 );
add_action( 'init', 'ninja_forms_set_save_sub' ); add_action( 'init', 'ninja_forms_set_save_sub' );
add_action( 'init', 'ninja_forms_edit_sub_remove_ajax_processing', 7 );
add_action( 'init', 'ninja_forms_edit_sub_pre_process', 999 ); add_action( 'init', 'ninja_forms_edit_sub_pre_process', 999 );
} }
function ninja_forms_edit_sub_remove_ajax_processing(){
global $ninja_forms_processing;
$ninja_forms_processing->update_form_setting( 'ajax', 0 );
}
function ninja_forms_edit_sub_pre_process(){ function ninja_forms_edit_sub_pre_process(){
global $ninja_forms_processing; global $ninja_forms_processing;
...@@ -630,4 +639,9 @@ function ninja_forms_view_subs_default_filter( $sub_results ) { ...@@ -630,4 +639,9 @@ function ninja_forms_view_subs_default_filter( $sub_results ) {
} }
add_filter( 'ninja_forms_view_subs_results', 'ninja_forms_view_subs_default_filter' ); add_filter( 'ninja_forms_view_subs_results', 'ninja_forms_view_subs_default_filter' );
add_filter( 'ninja_forms_download_all_subs_results', 'ninja_forms_view_subs_default_filter' ); add_filter( 'ninja_forms_download_all_subs_results', 'ninja_forms_view_subs_default_filter' );
\ No newline at end of file
function ninja_forms_edit_sub_remove_ajax( $form ){
$form['data']['ajax'] = 0;
return $form;
}
\ No newline at end of file
...@@ -12,22 +12,10 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){ ...@@ -12,22 +12,10 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
global $ninja_forms_processing; global $ninja_forms_processing;
if ( !is_object ( $ninja_forms_processing ) ) { if ( !is_object ( $ninja_forms_processing ) ) {
$field_row = ninja_forms_get_field_by_id( $field_id ); $field_row = ninja_forms_get_field_by_id( $field_id );
$form_id = $field_row['form_id']; $form_id = $field_row['form_id'];
if ( $field_row['type'] == '_calc' ) { if ( $field_row['type'] == '_calc' ) {
if ( !isset ( $ninja_forms_processing ) ) { //echo "Calc Filter";
$form_row = ninja_forms_get_form_by_field_id( $field_id );
$form_id = $form_row['id'];
$all_fields = ninja_forms_get_fields_by_form_id( $form_id );
$calc_array = array();
foreach ( $all_fields as $field ) {
if ( $field['type'] == '_calc' ) {
$calc_array[] = $field['id'];
}
}
}
// Figure out which method we are using to calculate this field. // Figure out which method we are using to calculate this field.
if ( isset ( $calc_data['calc_method'] ) ) { if ( isset ( $calc_data['calc_method'] ) ) {
$calc_method = $calc_data['calc_method']; $calc_method = $calc_data['calc_method'];
...@@ -53,8 +41,7 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){ ...@@ -53,8 +41,7 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
$all_fields = ninja_forms_get_fields_by_form_id( $form_id ); $all_fields = ninja_forms_get_fields_by_form_id( $form_id );
remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 ); remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11 );
// Figure out if there is a sub_total and a tax field. If there are, and this is a total field set to calc_method auto, we're using an equation, not auto. // Figure out if there is a sub_total and a tax field. If there are, and this is a total field set to calc_method auto, we're using an equation, not auto.
$tax = false; $tax = false;
$sub_total = false; $sub_total = false;
...@@ -79,6 +66,7 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){ ...@@ -79,6 +66,7 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
// Figure out how many calculation fields we have and run // Figure out how many calculation fields we have and run
$result = $calc_data['default_value']; $result = $calc_data['default_value'];
foreach ( $all_fields as $field ) { foreach ( $all_fields as $field ) {
if ( $field['id'] != $field_id ) { if ( $field['id'] != $field_id ) {
$field_data = apply_filters( 'ninja_forms_field', $field['data'], $field['id'] ); $field_data = apply_filters( 'ninja_forms_field', $field['data'], $field['id'] );
...@@ -122,16 +110,16 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){ ...@@ -122,16 +110,16 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
$calc_value = ninja_forms_calc_field_loop( $field['id'], $calc_eq ); $calc_value = ninja_forms_calc_field_loop( $field['id'], $calc_eq );
} else { } else {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method ); $calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
} }
if ( $calc_value !== false ) { if ( $calc_value !== false ) {
$calc_eq = preg_replace('/\bfield_'.$field['id'].'\b/', $calc_value, $calc_eq ); $calc_eq = preg_replace('/\bfield_'.$field['id'].'\b/', $calc_value, $calc_eq );
} }
} }
break; break;
} }
} }
} }
if ( $calc_method == 'eq' ) { if ( $calc_method == 'eq' ) {
$eq = new eqEOS(); $eq = new eqEOS();
$result = $eq->solveIF($calc_eq); $result = $eq->solveIF($calc_eq);
...@@ -196,6 +184,7 @@ function ninja_forms_calc_field_loop( $field_id, $calc_eq = '', $result = '' ){ ...@@ -196,6 +184,7 @@ function ninja_forms_calc_field_loop( $field_id, $calc_eq = '', $result = '' ){
// Figure out if there is a sub_total and a tax field. If there are, and this is a total field set to calc_method auto, we're using an equation, not auto. // Figure out if there is a sub_total and a tax field. If there are, and this is a total field set to calc_method auto, we're using an equation, not auto.
$tax = false; $tax = false;
$sub_total = false; $sub_total = false;
foreach ( $all_fields as $field ) { foreach ( $all_fields as $field ) {
$data = apply_filters( 'ninja_forms_field', $field['data'], $field['id'] ); $data = apply_filters( 'ninja_forms_field', $field['data'], $field['id'] );
...@@ -207,7 +196,7 @@ function ninja_forms_calc_field_loop( $field_id, $calc_eq = '', $result = '' ){ ...@@ -207,7 +196,7 @@ function ninja_forms_calc_field_loop( $field_id, $calc_eq = '', $result = '' ){
$sub_total = $field['id']; $sub_total = $field['id'];
} }
} }
// If the tax and sub_total have been found, and this is a total field set to auto, change the calc_method and calc_eq. // If the tax and sub_total have been found, and this is a total field set to auto, change the calc_method and calc_eq.
if ( $tax AND $sub_total AND isset ( $calc_data['payment_total'] ) AND $calc_data['payment_total'] == 1 AND $calc_method == 'auto' ) { if ( $tax AND $sub_total AND isset ( $calc_data['payment_total'] ) AND $calc_data['payment_total'] == 1 AND $calc_method == 'auto' ) {
$calc_method = 'eq'; $calc_method = 'eq';
...@@ -380,11 +369,11 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho ...@@ -380,11 +369,11 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho
} else { } else {
$field = ninja_forms_get_field_by_id( $field_id ); $field = ninja_forms_get_field_by_id( $field_id );
} }
//$field_data = $field['data']; //$field_data = $field['data'];
remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 2 ); //remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 );
$field_data = apply_filters( 'ninja_forms_field', $field['data'], $field_id ); $field_data = apply_filters( 'ninja_forms_field', $field['data'], $field_id );
add_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 ); //add_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 );
if ( isset ( $field_data['default_value'] ) ) { if ( isset ( $field_data['default_value'] ) ) {
$default_value = $field_data['default_value']; $default_value = $field_data['default_value'];
...@@ -395,7 +384,7 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho ...@@ -395,7 +384,7 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho
if ( $field_value == '' ) { if ( $field_value == '' ) {
$field_value = $default_value; $field_value = $default_value;
} }
$calc_value = 0; $calc_value = 0;
if ( $field['type'] == '_list' ) { if ( $field['type'] == '_list' ) {
if ( isset ( $field_data['list']['options'] ) ) { if ( isset ( $field_data['list']['options'] ) ) {
...@@ -424,9 +413,9 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho ...@@ -424,9 +413,9 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho
if ( !$field_value OR $field_value == '' ) { if ( !$field_value OR $field_value == '' ) {
$field_value = 0; $field_value = 0;
} }
$calc_value = $field_value; $calc_value = (float) preg_replace('/[^0-9.]*/','',$field_value);
} }
if ( is_string( $calc_value ) AND strpos( $calc_value, "%" ) !== false ) { if ( is_string( $calc_value ) AND strpos( $calc_value, "%" ) !== false ) {
$calc_value = str_replace( "%", "", $calc_value ); $calc_value = str_replace( "%", "", $calc_value );
$calc_value = $calc_value / 100; $calc_value = $calc_value / 100;
......
<?php
/*
*
* Function that filters default values, replacing defined strings with the approparite values.
*
* @since 2.2.49
* @return $data
*/
function ninja_forms_default_value_filter( $data, $field_id ) {
global $current_user;
if(isset($data['default_value'])){
$default_value = $data['default_value'];
}else{
$default_value = '';
}
get_currentuserinfo();
$user_ID = $current_user->ID;
$user_firstname = $current_user->user_firstname;
$user_lastname = $current_user->user_lastname;
$user_display_name = $current_user->display_name;
$user_email = $current_user->user_email;
switch( $default_value ){
case '_user_id':
$default_value = $user_ID;
break;
case 'user_firstname':
$default_value = $user_firstname;
break;
case 'user_lastname':
$default_value = $user_lastname;
break;
case '_user_display_name':
$default_value = $user_display_name;
break;
case 'user_email':
$default_value = $user_email;
break;
}
$data['default_value'] = $default_value;
return $data;
}
add_filter( 'ninja_forms_field', 'ninja_forms_default_value_filter', 9, 2 );
\ No newline at end of file
...@@ -74,6 +74,10 @@ function ninja_forms_display_fields($form_id){ ...@@ -74,6 +74,10 @@ function ninja_forms_display_fields($form_id){
$display_style = ''; $display_style = '';
} }
if ( $display_style != '' ) {
$display_style = 'style="'.$display_style.'"';
}
if ( $display_function != '' AND $show_field ) { if ( $display_function != '' AND $show_field ) {
if ( isset( $data['label_pos'] ) ) { if ( isset( $data['label_pos'] ) ) {
$label_pos = $data['label_pos']; $label_pos = $data['label_pos'];
...@@ -92,7 +96,7 @@ function ninja_forms_display_fields($form_id){ ...@@ -92,7 +96,7 @@ function ninja_forms_display_fields($form_id){
$field_wrap_class = apply_filters( 'ninja_forms_field_wrap_class', $field_wrap_class, $field_id ); $field_wrap_class = apply_filters( 'ninja_forms_field_wrap_class', $field_wrap_class, $field_id );
do_action( 'ninja_forms_display_before_opening_field_wrap', $field_id, $data ); do_action( 'ninja_forms_display_before_opening_field_wrap', $field_id, $data );
?> ?>
<div class="<?php echo $field_wrap_class;?>" style="<?php echo $display_style;?>" id="ninja_forms_field_<?php echo $field_id;?>_div_wrap"> <div class="<?php echo $field_wrap_class;?>" <?php echo $display_style;?> id="ninja_forms_field_<?php echo $field_id;?>_div_wrap">
<?php <?php
do_action( 'ninja_forms_display_after_opening_field_wrap', $field_id, $data ); do_action( 'ninja_forms_display_after_opening_field_wrap', $field_id, $data );
} }
......
...@@ -21,7 +21,7 @@ function ninja_forms_display_field_help( $field_id, $data ){ ...@@ -21,7 +21,7 @@ function ninja_forms_display_field_help( $field_id, $data ){
if($show_help){ if($show_help){
?> ?>
<img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>/images/question-ico.gif" title="<?php echo $help_text;?>"> <img class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>/images/question-ico.gif" title="<?php echo $help_text;?>">
<?php <?php
} }
} }
......
...@@ -120,6 +120,7 @@ function ninja_forms_display_form( $form_id = '' ){ ...@@ -120,6 +120,7 @@ function ninja_forms_display_form( $form_id = '' ){
} }
if($form_id != ''){ //Make sure that we have an active form_id. if($form_id != ''){ //Make sure that we have an active form_id.
$form_row = ninja_forms_get_form_by_id($form_id); $form_row = ninja_forms_get_form_by_id($form_id);
$form_row = apply_filters( 'ninja_forms_display_form_form_data', $form_row );
if( isset( $form_row['data']['ajax'] ) ){ if( isset( $form_row['data']['ajax'] ) ){
$ajax = $form_row['data']['ajax']; $ajax = $form_row['data']['ajax'];
}else{ }else{
......
...@@ -24,7 +24,7 @@ function ninja_forms_display_form_title( $form_id ){ ...@@ -24,7 +24,7 @@ function ninja_forms_display_form_title( $form_id ){
$form_title = ''; $form_title = '';
} }
$title_class = ''; $title_class = 'ninja-forms-form-title';
$title_class = apply_filters( 'ninja_forms_form_title_class', $title_class, $form_id ); $title_class = apply_filters( 'ninja_forms_form_title_class', $title_class, $form_id );
......
...@@ -819,6 +819,7 @@ class Ninja_Forms_Processing { ...@@ -819,6 +819,7 @@ class Ninja_Forms_Processing {
$data = $field['data']; $data = $field['data'];
$field_id = $field['id']; $field_id = $field['id'];
$user_value = $this->get_field_value( $field_id ); $user_value = $this->get_field_value( $field_id );
if ( isset ( $data['payment_total'] ) AND $data['payment_total'] == 1 ) { if ( isset ( $data['payment_total'] ) AND $data['payment_total'] == 1 ) {
$calc_method = $data['calc_method']; $calc_method = $data['calc_method'];
if ( isset ( $data['calc'] ) ) { if ( isset ( $data['calc'] ) ) {
...@@ -827,8 +828,9 @@ class Ninja_Forms_Processing { ...@@ -827,8 +828,9 @@ class Ninja_Forms_Processing {
$calc_eq = $data['calc_eq']; $calc_eq = $data['calc_eq'];
$places = $data['calc_places']; $places = $data['calc_places'];
$total_field = $field_id; $total_field = $field_id;
$total_value = number_format( round( $user_value, $places ), $places ); $total_value = number_format( round( $user_value, $places ), $places );
break; break;
} }
} }
...@@ -1032,57 +1034,70 @@ class Ninja_Forms_Processing { ...@@ -1032,57 +1034,70 @@ class Ninja_Forms_Processing {
// Loop through the fields // Loop through the fields
foreach ( $this->data['field_data'] as $field ) { foreach ( $this->data['field_data'] as $field ) {
$field_value = $this->get_field_value( $field['id'] ); $field_value = $this->get_field_value( $field['id'] );
switch ( $calc_method ) { // We don't want our field to be added if it's a tax field.
case 'auto': if ( $field['type'] != '_tax' ) {
// If this field's calc_auto_include is set to 1, then add this field's ID to the list. switch ( $calc_method ) {
if ( isset ( $field['data']['calc_auto_include'] ) AND $field['data']['calc_auto_include'] == 1 ) { case 'auto':
if ( $field['type'] != '_calc' ) { // If this field's calc_auto_include is set to 1, then add this field's ID to the list.
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method ); if ( isset ( $field['data']['calc_auto_include'] ) AND $field['data']['calc_auto_include'] == 1 ) {
if ( $calc_value ) { if ( $field['type'] != '_calc' ) {
$tmp_array[] = array( $field['id'] => $calc_value ); $calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
}
} else {
if ( $this->get_field_value( $field['id'] ) ) {
$tmp_array[] = array( $field['id'] => $this->get_field_value( $field['id'] ) );
}
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
} }
} else {
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
} }
} break;
break; case 'fields':
case 'fields': // If this field is in our list of field operations, add this field's ID to our list.
// If this field is in our list of field operations, add this field's ID to our list. if ( $calc_fields != '' ) {
if ( $calc_fields != '' ) { foreach ( $calc_fields as $calc ) {
foreach ( $calc_fields as $calc ) { if ( $field['id'] == $calc['field'] ) {
if ( $field['id'] == $calc['field'] ) { if ( $field['type'] != '_calc' ) {
//echo "FIELD ID: ".$field['id'];
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
}
} else {
if ( $this->get_field_value( $field['id'] ) ) {
$tmp_array[] = array( $field['id'] => $this->get_field_value( $field['id'] ) );
}
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
}
}
}
}
break;
case 'eq':
// If this field exists in our equation, then add this field's ID to our list.
if ( $calc_eq != '' ) {
if ( preg_match("/\bfield_".$field['id']."\b/i", $calc_eq ) ) {
if ( $field['type'] != '_calc' ) { if ( $field['type'] != '_calc' ) {
//echo "FIELD ID: ".$field['id'];
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method ); $calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) { if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value ); $tmp_array[] = array( $field['id'] => $calc_value );
} }
} else { } else {
if ( $this->get_field_value( $field['id'] ) ) {
$tmp_array[] = array( $field['id'] => $this->get_field_value( $field['id'] ) );
}
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that. // If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] ); $tmp_array[] = $this->get_calc_fields( $field['id'] );
} }
} }
} }
} break;
break; }
case 'eq':
// If this field exists in our equation, then add this field's ID to our list.
if ( $calc_eq != '' ) {
if ( preg_match("/\bfield_".$field['id']."\b/i", $calc_eq ) ) {
if ( $field['type'] != '_calc' ) {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
}
} else {
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
}
}
}
break;
} }
} }
// Loop through our array and make sure that it's not multi-dimensional. // Loop through our array and make sure that it's not multi-dimensional.
...@@ -1098,7 +1113,7 @@ class Ninja_Forms_Processing { ...@@ -1098,7 +1113,7 @@ class Ninja_Forms_Processing {
} }
} }
} }
return $calc_array; return $calc_array;
} }
......
<?php <?php
add_action('init', 'ninja_forms_register_fields_pre_process'); add_action('init', 'ninja_forms_register_fields_pre_process');
function ninja_forms_register_fields_pre_process(){ function ninja_forms_register_fields_pre_process(){
add_action('ninja_forms_pre_process', 'ninja_forms_fields_pre_process', 11 ); add_action( 'ninja_forms_pre_process', 'ninja_forms_fields_pre_process' );
} }
function ninja_forms_fields_pre_process(){ function ninja_forms_fields_pre_process(){
......
...@@ -156,6 +156,7 @@ function ninja_forms_display_js($form_id, $local_vars = ''){ ...@@ -156,6 +156,7 @@ function ninja_forms_display_js($form_id, $local_vars = ''){
} }
$form_row = ninja_forms_get_form_by_id($form_id); $form_row = ninja_forms_get_form_by_id($form_id);
$form_row = apply_filters( 'ninja_forms_display_form_form_data', $form_row );
if( isset( $form_row['data']['ajax'] ) ){ if( isset( $form_row['data']['ajax'] ) ){
$ajax = $form_row['data']['ajax']; $ajax = $form_row['data']['ajax'];
}else{ }else{
......
...@@ -20,7 +20,7 @@ function ninja_forms_register_field_calc(){ ...@@ -20,7 +20,7 @@ function ninja_forms_register_field_calc(){
'edit_custom_class' => false, 'edit_custom_class' => false,
'edit_help' => false, 'edit_help' => false,
//'process_field' => false, //'process_field' => false,
//'pre_process' => 'ninja_forms_field_calc_pre_process', //'pre_process' => 'ninja_forms_field_calc_strip_currency_symbol',
'edit_options' => array( 'edit_options' => array(
array( array(
'type' => 'hidden', 'type' => 'hidden',
...@@ -317,7 +317,7 @@ function ninja_forms_field_calc_edit( $field_id, $data ){ ...@@ -317,7 +317,7 @@ function ninja_forms_field_calc_edit( $field_id, $data ){
*/ */
function ninja_forms_field_calc_display( $field_id, $data ){ function ninja_forms_field_calc_display( $field_id, $data ){
if ( isset( $data['default_value'] ) ) { if ( isset( $data['default_value'] ) ) {
$default_value = $data['default_value']; $default_value = $data['default_value'];
} else { } else {
...@@ -486,6 +486,13 @@ function ninja_forms_field_calc_pre_process(){ ...@@ -486,6 +486,13 @@ function ninja_forms_field_calc_pre_process(){
$calc_eq = $field_data['calc_eq']; $calc_eq = $field_data['calc_eq'];
} else { } else {
$calc_eq = array(); $calc_eq = array();
}
// Get our calculation equation if it exists.
if ( isset ( $field_data['calc_places'] ) ) {
$calc_places = $field_data['calc_places'];
} else {
$calc_places = 0;
} }
$all_fields = $ninja_forms_processing->get_all_fields(); $all_fields = $ninja_forms_processing->get_all_fields();
...@@ -533,12 +540,11 @@ function ninja_forms_field_calc_pre_process(){ ...@@ -533,12 +540,11 @@ function ninja_forms_field_calc_pre_process(){
case 'auto': // We are automatically totalling the fields that have a calc_auto_include set to 1. case 'auto': // We are automatically totalling the fields that have a calc_auto_include set to 1.
if ( isset ( $field_data['calc_auto_include'] ) AND $field_data['calc_auto_include'] == 1 ) { if ( isset ( $field_data['calc_auto_include'] ) AND $field_data['calc_auto_include'] == 1 ) {
if ( $field['type'] == '_calc' ) { if ( $field['type'] == '_calc' ) {
$result = ninja_forms_calc_field_loop2( $field['id'], '', $result ); $calc_value = ninja_forms_calc_field_loop2( $field['id'], '', $result );
} else { }
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method ); $calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) { if ( $calc_value !== false ) {