forked from ajaxboy/cjax
/
overlay_validation.php
137 lines (112 loc) · 3.5 KB
/
overlay_validation.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
require_once 'ajax.php';
//$ajax->log = true;
$rules = array(
'rules' => array(
'a[name]' => array(
'required' => true,
'minlength' => 5,
),
'a[last_name]' => array(
'required' => true,
'minlength' => 5,
)
),
'messages' => array(
'a[name]' => array(
'required' => 'Please enter your name',
),
'a[last_name]' => array(
'required' => 'Enter your last name',
)
)
);
$overlay = $ajax->overLay('resources/html/test_form.html');
//surging from $overlay ensures that it is ran after the html has been generated.
$overlay->validate('button1','ajax.php?overlay_validation/form', $rules);
//die("cache<pre>".print_r(CoreEvents::$cache,1). "cbs<pre>".print_r(CoreEvents::$callbacks,1));
//ensure that it validation is ran after the html form is generated.
//$overlay->callback = $ajax->validate('button1','ajax.php?overlay_validation/form', $rules);
$ajax->click('link', $overlay);
$ajax->click('link2', $ajax->call('ajax.php?overlay_validation/overlay2'));
## Display the code that is used
$code = $ajax->code("
//5.0-RC3+
//Total 3 lines of code!, (not including the customs rules)
//Note: For sample#2 look inside the controller: examples/controllers/overlay_validation.php:overlay_validation::overlay2();
#Sample #1
//initial action to the 'launch' link
\$rules = array(
'rules' => array(
'a[name]' => array(
'required' => true,
'minlength' => 5,
),
'a[last_name]' => array(
'required' => true,
'minlength' => 5,
)
),
'messages' => array(
'a[name]' => array(
'required' => 'Please enter your name',
),
'a[last_name]' => array(
'required' => 'Enter your last name',
)
)
);
\$overlay = \$ajax->overLay('resources/html/test_form.html');
\$overlay->validate('button1','ajax.php?overlay_validation/form', \$rules);
\$ajax->click('link', \$overlay);
//Controller
class overlay_validation {
function form()
{
\$ajax = ajax();
//show posted variables
\$ajax->debug(\$_POST,'Post Debug Info',\"These are the fields posted.\");
}
}
");
$ajax->Exec('code', $ajax->overlayContent($code, array('width'=> '950px','top'=> '40px')));
?>
<head>
<?php echo $ajax->init();?>
<title>Ajax Overlay and Validation</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
</head>
<h2>Ajax Overlay and Validation</h2>
<br />
This sample makes use of different CJAX APIs to create a Overlay/validation functionality. The validation plugin makes use of
Jquery.validate plugin.
<br />
<br />
This sample can be downloaded along with 20+ demos here: <a href='http://cjax.sourceforge.net/examples/'>http://cjax.sourceforge.net/examples/</a>
<br /><br />
<br />
<a id='code' href='#'>View Code Used</a>
<br />
<br />
Used in sample:
<ul>
<li>
<a target='_blank' href='click_ajax_request.php'>$ajax->call()</a>
</li>
<li>
<a target='_blank' href='overlay.php'>$ajax->overLay()</a> (Used in Sample #1)
</li>
<li>
<a target='_blank' href='overlay.php'>$ajax->overlayContent()</a> (Used in Sample #2)
</li>
<li>
<a target='_blank' href='plugin_validate.php'>Cjax Plugin Jquery Validate</a>
</li>
</ul>
<a id='link' href='#'>Launch Sample #1</a>
<br />
<br />
<a id='link2' href='#'>Launch Sample #2</a>
<br />