/var/www/(Del)hsihk.com/wp-content/plugins/ninja-forms/includes/fields/timed-submit.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
function ninja_forms_register_field_timed_submit(){
    
$args = array(
        
'name' => __'Timed Submit''ninja-forms' ),
        
'edit_options' => array(
            array(
                
'type' => 'text',
                
'name' => 'label',
                
'label' => __'Label''ninja-forms' ),
                
'desc' => __'Submit button text after timer expires''ninja-forms' ),
                
'default' => __'Submit' ),
                
'class' => 'widefat ninja-forms-field-label'
            
),
            array(
                
'type' => 'text',
                
'name' => 'timer-text',
                
'label' => __'Label''ninja-forms' ),
                
'default' => __'Please wait %n seconds''ninja-forms' ),
                
'desc' => __'%n will be used to signify the number of seconds''ninja-forms' ),
                
'width' => 'wide',
                
'class' => 'widefat ninja-forms-field-label'
            
),
            array(
                
'type' => 'number',
                
'name' => 'countdown',
                
'label' => __'Number of seconds for countdown''ninja-forms' ),
                
'desc' => __'This is how long a user must wait to submit the form''ninja-forms' ),
                
'default' => 10,
            ),
        ),
        
'display_function' => 'ninja_forms_field_timed_submit_display',
        
'group' => 'standard_fields',
        
'edit_label' => false,
        
'edit_label_pos' => false,
        
'edit_req' => false,
        
'default_label' => __'Submit''ninja-forms' ),
        
'edit_desc' => false,
        
'edit_custom_class' => true,
        
'edit_help' => false,
        
'edit_meta' => false,
        
'sidebar' => 'template_fields',
        
'display_label' => false,
        
'edit_conditional' => true,
        
'conditional' => array(
            
'value' => array(
                
'type' => 'text',
            ),
        ),
        
'process_field' => false,
        
'pre_process' => 'ninja_forms_field_timed_submit_pre_process',
        
'limit' => 1,
        
'visible' => false
    
);

    
ninja_forms_register_field('_timed_submit'$args);
}

add_action('init''ninja_forms_register_field_timed_submit');



function 
ninja_forms_field_timed_submit_display$field_id$data$form_id '' ){

    
$field_class ninja_forms_get_field_class$field_id$form_id );

    if(isset(
$data['timer-text']) AND $data['timer-text'] != ''){
        
$label $data['timer-text'];
    }else{
        
$label __'Please wait %n seconds''ninja-forms' );
    }

    if(isset(
$data['countdown']) AND $data['countdown'] != ''){
        
$countdown $data['countdown'];
    }else{
        
$countdown '10';
    }

    if(isset(
$data['label']) AND $data['label'] != ''){
        
$submit_text $data['label'];
    }else{
        
$submit_text __'Submit''ninja-forms' );
    }

    
$label preg_replace"/%n/""<span>" $countdown "</span>"$label);
    
?>

    <input id="ninja_forms_field_<?php echo $field_id;?>_js" name="ninja_forms_field_<?php echo $field_id;?>[no-js]" type="hidden" value="1" rel="<?php echo $field_id;?>_js" class="no-js" />

    <button type="submit" name="ninja_forms_field_<?php echo $field_id;?>[timer]" class="<?php echo $field_class;?> countdown-timer" id="ninja_forms_field_<?php echo $field_id;?>" value="<?php echo $countdown;?>" rel="<?php echo $field_id;?>" data-countdown="<?php echo $countdown;?>" data-text="<?php esc_attr_e$submit_text );?>"><?php echo $label ;?></button>

    <?php

}

function 
ninja_forms_field_timed_submit_pre_process$field_id$user_value ){
    global 
$ninja_forms_processing;

    
$plugin_settings nf_get_settings();
    if ( isset ( 
$plugin_settings['timed_submit_error'] ) ) {
        
$timed_submit_error __$plugin_settings['timed_submit_error'], 'ninja-forms' );
    } else {
        
$timed_submit_error __('If you are a human, please slow down.''ninja-forms');
    }

    if ( isset ( 
$plugin_settings['javascript_error'] ) ) {
        
$javascript_error __$plugin_settings['javascript_error'], 'ninja-forms' );
    } else {
        
$javascript_error __'You need JavaScript to submit this form. Please enable it and try again.''ninja-forms' );
    }

    if ( isset ( 
$user_value['no-js'] ) ){
        
$ninja_forms_processing->add_error('javascript-general'$javascript_error'general' );
    } else {
        
$timer = isset( $user_value['timer'] ) ? $user_value['timer'] : 10;
        if( 
intval$timer ) > ){
           
$ninja_forms_processing->add_error('timer-'.$field_id$timed_submit_error$field_id);
        }
    }



}