index.php

Gesponsorde koppelingen

PHP script bestanden

  1. index.php
  2. validation.class.php

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php

require_once('validation.class.php');

$validation = new Validation();

?>


<!DOCTYPE html>
<html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<head>
    <link rel="stylesheet" href="main.css" />
</head>

<body>

<div class="container">

<h1>Form Validation Class</h1>

<?php        
    //Set rules for the 'name' field
    $field = 'name';
    $validationRules = array(      
                           'required' => TRUE,
                           'minLength' => 2,
                           'maxLength' => 15,
                           'alphaNumeric' => TRUE
                       );
    $validation->setValidation($field, $validationRules);

    //Set rules for the 'email' field
    $field = 'email';
    $validationRules = array(
                           'required' => true,
                           'minLength' => 2,
                           'maxLength' => 40,
                           'validEmail' => true
                       );
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'website' field
    $field = 'website';
    $validationRules = array(
                           'minLength' => 2,
                           'maxLength' => 40,
                           'validURL' => true
                       );
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'password' field
    $field = 'password';
    $validationRules = array(
                           'required' => true,
                           'minLength' => 2,
                           'maxLength' => 10,
                           'aplhaNumeric' => TRUE
                       );                      
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'passwordConfirm' field
    $field = 'passwordConfirm';
    $validationRules = array(        
                           'minLength' => 2,
                           'maxLength' => 10,
                           'aplhaNumeric' => TRUE,
                           'match' => 'password'
                       );
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'passwordConfirm' field
    $field = 'lower';
    $validationRules = array(        
                           'numeric' => TRUE,
                           'lessThan' => 10
                       );
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'passwordConfirm' field
    $field = 'higher';
    $validationRules = array(        
                           'numeric' => TRUE,
                           'greaterThan' => 10
                       );
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'team' select dropdown
    $field = 'team';
    $validationRules = array(            
                           'required' => TRUE
                       );
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'language' radio button(s)
    $field = 'language';
    $validationRules = array(            
                           'required' => TRUE
                       );
    $validation->setValidation($field, $validationRules);
    
    //Set rules for the 'terms' checkbox
    $field = 'terms';
    $validationRules = array(            
                           'required' => TRUE
                       );
    $validation->setValidation($field, $validationRules);

    
    //Validate the fields (has to be called after the validationRules have been set and before the fields)
    if(isset($_POST['form_submit']))
    {

        if($validation->validateFields($_POST))
        {

            //validateFields() returns TRUE, Process the data in a database
        }
    }


    
    //Open the form
    echo $validation->openForm('index.php', 'POST');
    
    //Set a text field
    echo $validation->setField('text', 'name', 'Name');
    
    //Set a text field
    echo $validation->setField('text', 'email', 'Email');
    
    //Set a text field
    echo $validation->setField('text', 'website', 'Website', 'example: www.my-website.com');
    
    //Set a password field
    echo $validation->setField('password', 'password', 'Password');
    
    //Set a password field
    echo $validation->setField('password', 'passwordConfirm', 'Confirm Password', 'Has to match Password');
    
    //Set a lower field
    echo $validation->setField('text', 'lower', 'Type a number lower than 10');
    
    //Set a higher field
    echo $validation->setField('text', 'higher', 'Type a number higher than 10');
        
    //Set a select dropdown menu
    $selectOptions = array(
                         'Real Madrid' => 'real_madrid',
                         'Barcelona' => 'barcelona',
                         'Chelsea' => 'chelsea',
                         'Bayern Munchen' => 'bayern_munchen'
                     );
    echo $validation->setSelect('team', 'Champions League winner', $selectOptions, 'Halla Madrid');
    
    //Set radio buttons
    $radioOptions = array(
                        'English' => 'english',
                        'Dutch' => 'dutch'
                    );
    echo $validation->setRadio('language', 'Language', $radioOptions);
    
    //Set a checkbox
    echo $validation->setCheckbox('terms', 'I accept the terms and conditions');    
    
    //Set the submit button
    echo $validation->setSubmit('form_submit', 'Submit');
    
    //Close the form
    echo $validation->closeForm();
?>


</div><!-- End container -->

</body>

<html>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.