|
1
|
|
|
<?php |
|
2
|
|
|
// Include CForm |
|
3
|
|
|
include('../../autoloader.php'); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Create a class for a contact-form with name, email and phonenumber. |
|
8
|
|
|
*/ |
|
9
|
|
|
class CFormContact extends \Mos\HTMLForm\CForm { |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** Create all form elements and validation rules in the constructor. |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct() { |
|
16
|
|
|
parent::__construct(); |
|
17
|
|
|
|
|
18
|
|
|
$this->AddElement(new \Mos\HTMLForm\CFormElementText('name')) |
|
|
|
|
|
|
19
|
|
|
->AddElement(new \Mos\HTMLForm\CFormElementText('email')) |
|
20
|
|
|
->AddElement(new \Mos\HTMLForm\CFormElementText('phone')) |
|
21
|
|
|
->AddElement(new \Mos\HTMLForm\CFormElementSubmit('submit', array('callback'=>array($this, 'DoSubmit')))) |
|
|
|
|
|
|
22
|
|
|
->AddElement(new \Mos\HTMLForm\CFormElementSubmit('submit-fail', array('callback'=>array($this, 'DoSubmitFail')))); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Callback for submitted forms, will always fail |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function DoSubmitFail() { |
|
30
|
|
|
echo "<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>"; |
|
31
|
|
|
return false; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Callback for submitted forms |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function DoSubmit() { |
|
39
|
|
|
echo "<p><i>DoSubmit(): Form was submitted. Do stuff (save to database) and return true (success) or false (failed processing form)</i></p>"; |
|
40
|
|
|
return true; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
// ----------------------------------------------------------------------- |
|
47
|
|
|
// |
|
48
|
|
|
// Use the form and check it status. |
|
49
|
|
|
// |
|
50
|
|
|
session_name('cform_example'); |
|
51
|
|
|
session_start(); |
|
52
|
|
|
$form = new CFormContact(); |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
// Check the status of the form |
|
56
|
|
|
$status = $form->Check(); |
|
57
|
|
|
|
|
58
|
|
|
// What to do if the form was submitted? |
|
59
|
|
|
if($status === true) { |
|
60
|
|
|
echo "<p><i>Form was submitted and the callback method returned true. I should redirect to a page to avoid issues with reloading posted form.</i></p>"; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// What to do when form could not be processed? |
|
64
|
|
|
else if($status === false){ |
|
65
|
|
|
echo "<p><i>Form was submitted and the callback method returned false. I should redirect to a page to avoid issues with reloading posted form.</i></p>"; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
?> |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
<!doctype html> |
|
72
|
|
|
<meta charset=utf8> |
|
73
|
|
|
<title>CForm Example: Basic example on how to use CForm (part 3)</title> |
|
74
|
|
|
<h1>CForm Example: Basic example on how to use CForm (part 3)</h1> |
|
75
|
|
|
<?=$form->GetHTML()?> |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
<p><code>$_POST</code> <?php if(empty($_POST)) {echo '<i>is empty.</i>';} else {echo '<i>contains:</i><pre>' . print_r($_POST, 1) . '</pre>';} ?></p> |
|
79
|
|
|
|
|
80
|
|
|
<?php $footer = "footer_mos.php"; if(is_file($footer)) include($footer) ?> |
|
81
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths