SHOW:
|
|
- or go back to the newest paste.
1 | - | if (empty($_POST) || !SmartyValidate::is_registered_form('ContactForm')) |
1 | + | <?php |
2 | - | { |
2 | + | session_start(); |
3 | - | SmartyValidate::connect($smarty, true); |
3 | + | |
4 | - | SmartyValidate::register_form('ContactForm', true); |
4 | + | // load Smarty library |
5 | - | SmartyValidate::register_validator('checkContactName', 'contactName', 'notEmpty', false, false, 'trim', 'ContactForm'); |
5 | + | require('Smarty.class.php'); |
6 | - | SmartyValidate::register_validator('checkContactComment', 'contactComment', 'notEmpty', false, false, 'trim', 'ContactForm'); |
6 | + | require('SmartyValidate.class.php'); |
7 | - | SmartyValidate::register_validator('checkContactEmail', 'contactEmail', 'isEmail', false, false, 'trim', 'ContactForm'); |
7 | + | |
8 | $smarty = new Smarty; | |
9 | - | else |
9 | + | |
10 | - | { |
10 | + | $smarty->template_dir = 'c:/inetpub/wwwroot/smarty/templates'; |
11 | - | SmartyValidate::connect($smarty); |
11 | + | $smarty->config_dir = ' c:/inetpub/wwwroot/smarty/config'; |
12 | - | if(SmartyValidate::is_valid($_POST,'ContactForm')) |
12 | + | $smarty->cache_dir = 'c:/smarty/smarty_cache'; |
13 | - | { |
13 | + | $smarty->compile_dir = 'c:/smarty/smarty_templates_c'; |
14 | - | SmartyValidate::disconnect(); |
14 | + | |
15 | - | } |
15 | + | if(empty($_POST)) { |
16 | - | else |
16 | + | // new form, we (re)set the session data |
17 | - | { |
17 | + | |
18 | - | $smarty->assign($_POST); |
18 | + | SmartyValidate::connect($smarty, true); |
19 | - | } |
19 | + | // register our validators |
20 | - | } |
20 | + | SmartyValidate::register_validator('fullname', 'FullName', 'notEmpty', |
21 | false, false, 'trim'); | |
22 | SmartyValidate::register_validator('phone', 'Phone', 'isNumber', true, | |
23 | false, 'trim'); | |
24 | SmartyValidate::register_validator('expdate', 'CCExpDate', 'notEmpty', | |
25 | false, false, 'trim'); | |
26 | SmartyValidate::register_validator('email', 'Email', 'isEmail', false, | |
27 | false, 'trim'); | |
28 | SmartyValidate::register_validator('date', 'Date', 'isDate', true, | |
29 | false, 'trim'); | |
30 | SmartyValidate::register_validator('password', 'password:password2', 'isEqual'); | |
31 | // display form | |
32 | $smarty->display('form.tpl'); | |
33 | } else { | |
34 | // validate after a POST | |
35 | SmartyValidate::connect($smarty); | |
36 | if(SmartyValidate::is_valid($_POST)) { | |
37 | // no errors, done with SmartyValidate | |
38 | SmartyValidate::disconnect(); | |
39 | $smarty->display('success.tpl'); | |
40 | } else { | |
41 | // error, redraw the form | |
42 | $smarty->assign($_POST); | |
43 | $smarty->display('form.tpl'); | |
44 | } | |
45 | } | |
46 | ||
47 | ?> |