Code Duplication    Length = 38-38 lines in 4 locations

main/inc/lib/formvalidator/FormValidator.class.php 4 locations

@@ 1115-1152 (lines=38) @@
1112
     * @param bool $required Optional. Is the form-element required (default=true)
1113
     * @param array $attributes Optional. List of attributes for the form-element
1114
     */
1115
    public function addTextLettersOnly(
1116
        $name,
1117
        $label,
1118
        $required = false,
1119
        $attributes = []
1120
    ) {
1121
        $attributes = array_merge(
1122
            $attributes,
1123
            [
1124
                'pattern' => '[a-zA-ZñÑ]+',
1125
                'title' => get_lang('OnlyLetters')
1126
            ]
1127
        );
1128
1129
        $this->addElement(
1130
            'text',
1131
            $name,
1132
            [
1133
                $label,
1134
                get_lang('OnlyLetters')
1135
            ],
1136
            $attributes
1137
        );
1138
1139
        $this->applyFilter($name, 'trim');
1140
1141
        if ($required) {
1142
            $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
1143
        }
1144
1145
        $this->addRule(
1146
            $name,
1147
            get_lang('OnlyLetters'),
1148
            'regex',
1149
            '/^[a-zA-ZñÑ]+$/'
1150
        );
1151
    }
1152
1153
    /**
1154
     * Adds a text field for alphanumeric characters to the form.
1155
     * A trim-filter is attached to the field.
@@ 1161-1198 (lines=38) @@
1158
     * @param bool $required Optional. Is the form-element required (default=true)
1159
     * @param array $attributes Optional. List of attributes for the form-element
1160
     */
1161
    public function addTextAlphanumeric(
1162
        $name,
1163
        $label,
1164
        $required = false,
1165
        $attributes = []
1166
    ) {
1167
        $attributes = array_merge(
1168
            $attributes,
1169
            [
1170
                'pattern' => '[a-zA-Z0-9ñÑ]+',
1171
                'title' => get_lang('OnlyLettersAndNumbers')
1172
            ]
1173
        );
1174
1175
        $this->addElement(
1176
            'text',
1177
            $name,
1178
            [
1179
                $label,
1180
                get_lang('OnlyLettersAndNumbers')
1181
            ],
1182
            $attributes
1183
        );
1184
1185
        $this->applyFilter($name, 'trim');
1186
1187
        if ($required) {
1188
            $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
1189
        }
1190
1191
        $this->addRule(
1192
            $name,
1193
            get_lang('OnlyLettersAndNumbers'),
1194
            'regex',
1195
            '/^[a-zA-Z0-9ÑÑ]+$/'
1196
        );
1197
    }
1198
1199
    /**
1200
     * Adds a text field for letters and spaces to the form.
1201
     * A trim-filter is attached to the field.
@@ 1207-1244 (lines=38) @@
1204
     * @param bool $required Optional. Is the form-element required (default=true)
1205
     * @param array $attributes Optional. List of attributes for the form-element
1206
     */
1207
    public function addTextLettersAndSpaces(
1208
        $name,
1209
        $label,
1210
        $required = false,
1211
        $attributes = []
1212
    ) {
1213
        $attributes = array_merge(
1214
            $attributes,
1215
            [
1216
                'pattern' => '[a-zA-ZñÑ\s]+',
1217
                'title' => get_lang('OnlyLettersAndSpaces')
1218
            ]
1219
        );
1220
1221
        $this->addElement(
1222
            'text',
1223
            $name,
1224
            [
1225
                $label,
1226
                get_lang('OnlyLettersAndSpaces')
1227
            ],
1228
            $attributes
1229
        );
1230
1231
        $this->applyFilter($name, 'trim');
1232
1233
        if ($required) {
1234
            $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
1235
        }
1236
1237
        $this->addRule(
1238
            $name,
1239
            get_lang('OnlyLettersAndSpaces'),
1240
            'regex',
1241
            '/^[a-zA-ZñÑ\s]+$/'
1242
        );
1243
    }
1244
1245
    /**
1246
     * Adds a text field for alphanumeric and spaces characters to the form.
1247
     * A trim-filter is attached to the field.
@@ 1253-1290 (lines=38) @@
1250
     * @param bool $required Optional. Is the form-element required (default=true)
1251
     * @param array $attributes Optional. List of attributes for the form-element
1252
     */
1253
    public function addTextAlphanumericAndSpaces(
1254
        $name,
1255
        $label,
1256
        $required = false,
1257
        $attributes = []
1258
    ) {
1259
        $attributes = array_merge(
1260
            $attributes,
1261
            [
1262
                'pattern' => '[a-zA-Z0-9ñÑ\s]+',
1263
                'title' => get_lang('OnlyLettersAndNumbersAndSpaces')
1264
            ]
1265
        );
1266
1267
        $this->addElement(
1268
            'text',
1269
            $name,
1270
            [
1271
                $label,
1272
                get_lang('OnlyLettersAndNumbersAndSpaces')
1273
            ],
1274
            $attributes
1275
        );
1276
1277
        $this->applyFilter($name, 'trim');
1278
1279
        if ($required) {
1280
            $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
1281
        }
1282
1283
        $this->addRule(
1284
            $name,
1285
            get_lang('OnlyLettersAndNumbersAndSpaces'),
1286
            'regex',
1287
            '/^[a-zA-Z0-9ñÑ\s]+$/'
1288
        );
1289
    }
1290
1291
    /**
1292
     * @param string $url
1293
     */