nf_clear_complete

Function that resets the field values to default if the form has been submitted.

Description

nf_clear_complete( $form_id ); 

Parameters (1)

0. $form_id
The form id.

Usage

  1. if ( !function_exists( 'nf_clear_complete' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/display/fields/clear-complete.php'; 
  3.  
  4. // The form id. 
  5. $form_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = nf_clear_complete($form_id); 
  9.  

Defined (1)

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

/deprecated/includes/display/fields/clear-complete.php  
  1. function nf_clear_complete( $form_id ) { 
  2. global $ninja_forms_processing, $current_user, $post; 
  3.  
  4. if ( ! isset ( $ninja_forms_processing ) or $ninja_forms_processing->get_form_setting( 'clear_complete' ) == 0 or $ninja_forms_processing->get_form_setting( 'processing_complete' ) != 1 ) 
  5. return false; 
  6.  
  7. $all_fields = $ninja_forms_processing->get_all_fields(); 
  8. foreach ( $all_fields as $field_id => $user_value ) { 
  9. $default_value = $ninja_forms_processing->get_field_setting( $field_id, 'default_value' ); 
  10.  
  11. wp_get_current_user(); 
  12. $user_ID = $current_user->ID; 
  13. if ( $user_ID and !empty( $user_ID ) ) { 
  14. $user_firstname = $current_user->user_firstname; 
  15. $user_lastname = $current_user->user_lastname; 
  16. $user_display_name = $current_user->display_name; 
  17. $user_email = $current_user->user_email; 
  18. } else { 
  19. $user_ID = ''; 
  20. $user_firstname = ''; 
  21. $user_lastname = ''; 
  22. $user_display_name = ''; 
  23. $user_email = ''; 
  24.  
  25.  
  26. if ( is_object ( $post ) ) { 
  27. $post_ID = $post->ID; 
  28. $post_title = $post->post_title; 
  29. $post_url = get_permalink( $post_ID ); 
  30. } else { 
  31. $post_ID = ''; 
  32. $post_title = ''; 
  33. $post_url = ''; 
  34.  
  35. switch( $default_value ) { 
  36. case '_user_id': 
  37. $default_value = $user_ID; 
  38. break; 
  39. case '_user_firstname': 
  40. $default_value = $user_firstname; 
  41. break; 
  42. case '_user_lastname': 
  43. $default_value = $user_lastname; 
  44. break; 
  45. case '_user_display_name': 
  46. $default_value = $user_display_name; 
  47. break; 
  48. case '_user_email': 
  49. $default_value = $user_email; 
  50. break; 
  51. case 'post_id': 
  52. $default_value = $post_ID; 
  53. break; 
  54. case 'post_title': 
  55. $default_value = $post_title; 
  56. break; 
  57. case 'post_url': 
  58. $default_value = $post_url; 
  59. break; 
  60. case 'today': 
  61. $plugin_settings = nf_get_settings(); 
  62. if ( isset ( $plugin_settings['date_format'] ) ) { 
  63. $date_format = $plugin_settings['date_format']; 
  64. } else { 
  65. $date_format = 'm/d/Y'; 
  66. $default_value = date( $date_format, current_time( 'timestamp' ) ); 
  67. break; 
  68.  
  69.  
  70.  
  71. $ninja_forms_processing->update_field_value( $field_id, $default_value );