FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
forms/example.php at main · mintyphp/forms · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
mintyphp
/
forms
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
forms
/
example.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (49 loc) · 1.62 KB
Breadcrumbs
forms
/
example.php
Copy path
File metadata and controls
57 lines (49 loc) · 1.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
// alias the most used classes
use
MintyPHP
\
Form
\
Elements
as
E
;
use
MintyPHP
\
Form
\
Validator
\
Validators
as
V
;
// ensure all classes are (auto)loaded:
require_once
'
vendor/autoload.php
'
;
// set style to Bulma
E::
$
style
=
'
bulma
'
;
// create a form object
$
form
= E::
form
([
E::
field
(E::
text
(
'
username
'
)->
required
(), E::
label
(
'
Username
'
), [V::
minLength
(
1
)]),
E::
field
(E::
password
(
'
password
'
), E::
label
(
'
Password
'
)),
E::
field
(E::
submit
(
'
Login
'
)),
]);
// check if the form has been submitted
if
(
$
_SERVER
[
'
REQUEST_METHOD
'
] ==
'
POST
'
) {
// fill the form with the submitted data
$
form
->
fill
(
$
_POST
);
// if the form is valid, process the data
if
(
$
form
->
validate
()) {
// extract the data
$
data
=
$
form
->
extract
();
// process the data (e.g., login, save to database, etc.)
if
(
$
data
[
'
username
'
] ==
'
user
'
&&
$
data
[
'
password
'
] ==
'
pass
'
) {
// redirect to the dashboard page
die
(
'
logged in, redirecting to dashboard...
'
);
}
else
{
// invalidate credentials
$
form
->
addErrors
([
'
username
'
=>
'
Invalid username/password combination
'
,
'
password
'
=>
'
Invalid username/password combination
'
,
]);
}
}
}
else
{
// if the form is not submitted, fill it with empty values
$
form
->
fill
([
'
username
'
=>
''
,
'
password
'
=>
''
]);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/1.0.3/css/bulma.min.css">
</head>
<body class="container p-5">
<h1 class="title">Login</h1>
<?php
$
form
->
render
();
?>
</body>
</html>
Back
|
FazBrowse Home
|
New Git URL