Zit met probleem:
en deze code om de class te testen.
Werkt goed zover, alleen als ik nu dit doe:
Dan werkt while-loop niet! Hij print niet de keys uit, terwijl
de arrays (gezien scriptje helemaal onderaan) toch echt wel keys hebben!
Weet iemand wat er aan de hand kan zijn?
Voor duidelijkheid: scriptje tussen de ******* print NIKS!
en dat hadden paar regels moeten zijn!
Dank dank!
code:
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
| <?php
// validation class
class validate {
// declare all required variables
var $result = array();
// call all required functions
function check_($data) {
if(array_key_exists("emptystring_", $data))
$this->emptystring_($data["emptystring_"]);
if(array_key_exists("passwordmatch_", $data))
$this->passwordmatch_($data["passwordmatch_"]);
if(array_key_exists("count_", $data))
$this->count_($data["count_"]);
if(array_key_exists("illegal_", $data))
$this->illegal_($data["illegal_"]);
}
// check for an empty string
function emptystring_($empty) {
if ($empty == "")
$this->result["emptystring_"] = "false";
}
// check if the passwords match
function passwordmatch_($passwords) {
if ($passwords[0] != $passwords[1])
$this->result["passwordmatch_"] = "false";
}
// check if field contains an allowed amount of carachters
function count_($count) {
if (strlen($count[0]) < $count[1] || strlen($count[0]) > $count[2])
$this->result["count_"] = "false";
}
// check if field contains illegal characters
function illegal_($illegal) {
if(ereg('[^a-z0-9]', $illegal))
$this->result["illegal_"] = "false";
}
}
?> |
en deze code om de class te testen.
Werkt goed zover, alleen als ik nu dit doe:
code:
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
| <?php
// class test //
$_POST["username"] = "#%e";
$_POST["password"] = "";
// validate input with a class.
include ("..\extend\validate_class.php");
$validate = new Validate;
// check $_POST["username"]
$input = array($_POST["username"], $_POST["password"]);
$process = array("count_" => array($input[0], 5, 10),
"emptystring_" => $input[0] ,
"passwordmatch_" => array($input[0], $input[1]),
"illegal_" => $input[0]);
$validate->check_($process);
// see whats up in the array!
foreach ($validate->result as $output) {
echo "$output. <br>";
}
print "<br><br>*******************************************************<br><br>";
while ($zorf = current($validate->result)) {
if ($zorf == "false") {
echo key($validate->result) . "<br>";
}
next($validate->result);
}
print "<br><br>*******************************************************<br><br>";
print_r(array_keys($validate->result, "false"));
?> |
Dan werkt while-loop niet! Hij print niet de keys uit, terwijl
de arrays (gezien scriptje helemaal onderaan) toch echt wel keys hebben!
Weet iemand wat er aan de hand kan zijn?
Voor duidelijkheid: scriptje tussen de ******* print NIKS!
en dat hadden paar regels moeten zijn!
Dank dank!
mijn naam slaat nergens op, althans niet op mij :P