response-message.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /*
  3. * Outputs the HTML for displaying success messages or error messages set to display at location 'general'
  4. *
  5. */
  6. function ninja_forms_display_response_message( $form_id ){
  7. global $ninja_forms_processing;
  8. // if ( ! is_object( $ninja_forms_processing ) || $ninja_forms_processing->get_form_ID() != $form_id ) {
  9. // return false;
  10. // }
  11. $plugin_settings = nf_get_settings();
  12. $form_row = ninja_forms_get_form_by_id($form_id);
  13. if( isset( $form_row['data']['ajax'] ) ){
  14. $ajax = $form_row['data']['ajax'];
  15. }else{
  16. $ajax = 0;
  17. }
  18. if( $ajax == 0 AND ( is_object( $ninja_forms_processing ) AND !$ninja_forms_processing->get_all_errors() AND !$ninja_forms_processing->get_all_success_msgs() ) ){
  19. $display = 'display:none;';
  20. }else{
  21. $display = '';
  22. }
  23. if( is_object( $ninja_forms_processing ) ){
  24. if( $ninja_forms_processing->get_errors_by_location('general') ){
  25. $class = 'ninja-forms-error-msg';
  26. }else if( $ninja_forms_processing->get_all_success_msgs() ){
  27. $class = 'ninja-forms-success-msg';
  28. }else{
  29. $class = '';
  30. }
  31. }else{
  32. $class = '';
  33. }
  34. $class = apply_filters( 'ninja_forms_display_response_message_class', $class, $form_id );
  35. //if ( $class != '' ) {
  36. echo '<div id="ninja_forms_form_' . $form_id . '_response_msg" style="' . $display . '" class="ninja-forms-response-msg '.$class.'">';
  37. if ( isset ( $ninja_forms_processing ) && $ninja_forms_processing->get_form_ID() == $form_id ) {
  38. if( is_object( $ninja_forms_processing ) ){
  39. if( $ninja_forms_processing->get_form_ID() == $form_id ){
  40. if( $ninja_forms_processing->get_errors_by_location('general') ){
  41. foreach($ninja_forms_processing->get_errors_by_location('general') as $error){
  42. echo '<div>';
  43. echo $error['msg'];
  44. echo '</div>';
  45. }
  46. }
  47. if( $ninja_forms_processing->get_all_success_msgs()){
  48. foreach($ninja_forms_processing->get_all_success_msgs() as $success){
  49. echo '<div>';
  50. echo $success;
  51. echo '</div>';
  52. }
  53. }
  54. }
  55. }
  56. }
  57. echo '</div>';
  58. //}
  59. }
  60. add_action( 'ninja_forms_display_before_form', 'ninja_forms_display_response_message', 10 );