-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
743 lines (468 loc) · 32.1 KB
/
index.html
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="canonical" href="https://formr.github.io/">
<link rel="icon" href="assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.3.0, mkdocs-material-8.3.4">
<title>Formr</title>
<link rel="stylesheet" href="assets/stylesheets/main.4a0965b7.min.css">
<link rel="stylesheet" href="assets/stylesheets/palette.cbb835fc.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="stylesheets/extra.css">
<script>__md_scope=new URL(".",location),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="" data-md-color-primary="none" data-md-color-accent="none">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#formr" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href="." title="Formr" class="md-header__button md-logo" aria-label="Formr" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Formr
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Home
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="." title="Formr" class="md-nav__button md-logo" aria-label="Formr" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
Formr
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
Home
<span class="md-nav__icon md-icon"></span>
</label>
<a href="." class="md-nav__link md-nav__link--active">
Home
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#features" class="md-nav__link">
Features
</a>
</li>
<li class="md-nav__item">
<a href="#installation" class="md-nav__link">
Installation
</a>
<nav class="md-nav" aria-label="Installation">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#composer" class="md-nav__link">
Composer
</a>
</li>
<li class="md-nav__item">
<a href="#download" class="md-nav__link">
Download
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#frameworks" class="md-nav__link">
Frameworks
</a>
</li>
<li class="md-nav__item">
<a href="#quick-start" class="md-nav__link">
Quick Start
</a>
<nav class="md-nav" aria-label="Quick Start">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#1-create-the-form" class="md-nav__link">
1. Create the Form
</a>
</li>
<li class="md-nav__item">
<a href="#2-build-the-form" class="md-nav__link">
2. Build the Form
</a>
</li>
<li class="md-nav__item">
<a href="#3-get-the-values" class="md-nav__link">
3. Get the Values
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#full-example" class="md-nav__link">
Full Example
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="methods/" class="md-nav__link">
Methods
</a>
</li>
<li class="md-nav__item">
<a href="properties/" class="md-nav__link">
Properties
</a>
</li>
<li class="md-nav__item">
<a href="validation/" class="md-nav__link">
Validation
</a>
</li>
<li class="md-nav__item">
<a href="upload-files/" class="md-nav__link">
Upload Files
</a>
</li>
<li class="md-nav__item">
<a href="fastform/" class="md-nav__link">
FastForm
</a>
</li>
<li class="md-nav__item">
<a href="https://github.com/formr/extend" class="md-nav__link">
Extend
</a>
</li>
<li class="md-nav__item">
<a href="blog/" class="md-nav__link">
Blog
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#features" class="md-nav__link">
Features
</a>
</li>
<li class="md-nav__item">
<a href="#installation" class="md-nav__link">
Installation
</a>
<nav class="md-nav" aria-label="Installation">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#composer" class="md-nav__link">
Composer
</a>
</li>
<li class="md-nav__item">
<a href="#download" class="md-nav__link">
Download
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#frameworks" class="md-nav__link">
Frameworks
</a>
</li>
<li class="md-nav__item">
<a href="#quick-start" class="md-nav__link">
Quick Start
</a>
<nav class="md-nav" aria-label="Quick Start">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#1-create-the-form" class="md-nav__link">
1. Create the Form
</a>
</li>
<li class="md-nav__item">
<a href="#2-build-the-form" class="md-nav__link">
2. Build the Form
</a>
</li>
<li class="md-nav__item">
<a href="#3-get-the-values" class="md-nav__link">
3. Get the Values
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#full-example" class="md-nav__link">
Full Example
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="formr">Formr</h1>
<p>Formr is a simple, yet powerful PHP form builder which enables you to create and validate your forms in seconds.</p>
<p>If you find Formr useful, please consider starring the <a href="https://github.com/formr/formr">project</a> and making a <a href="https://paypal.me/timgavin">donation</a>. Thank you!</p>
<p><a href="https://packagist.org/packages/formr/formr"><img alt="Latest Version on Packagist" src="https://img.shields.io/packagist/v/formr/formr.svg" /></a>
<a href="https://packagist.org/packages/formr/formr"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/formr/formr.svg" /></a>
<a href="https://github.com/formr/formr/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/formr/formr" /></a>
<a href="https://github.com/formr/formr/network"><img alt="GitHub forks" src="https://img.shields.io/github/forks/formr/formr" /></a>
<a href="https://github.com/formr/formr/issues"><img alt="GitHub issues" src="https://img.shields.io/github/issues/formr/formr" /></a>
<a href="https://github.com/formr/Formr/blob/master/license.txt"><img alt="GitHub license" src="https://img.shields.io/github/license/formr/formr" /></a></p>
<h2 id="features">Features</h2>
<ul>
<li>Create complex forms with server-side processing and validation in seconds</li>
<li>Built-in support for Bootstrap and Bulma</li>
<li>Built-in support for reCAPTCHA v3</li>
<li>Built-in <code>POST</code> validation rules, including validating email, regex, comparisons, slugging, and hashing</li>
<li>Instantly make one field required, all fields required, or all but one field required</li>
<li>Create and validate radio groups and checkbox arrays in seconds</li>
<li>Upload images: resize, rename, and create thumbnails</li>
<li>Extensible: easily create and save your own field element wrappers</li>
<li>Extensible: easily create and save your own dropdown menus</li>
<li>Extensible: easily create and save your own form & validation sets</li>
<li>Send plain text and HTML emails</li>
<li>Generate CSRF tokens and honeypots</li>
<li>Object-oriented; supports multiple forms per page</li>
<li>Little helpers to assist in building, layout, testing and debugging</li>
<li>And a ton of other cool stuff!</li>
</ul>
<h2 id="installation">Installation</h2>
<h4 id="composer">Composer</h4>
<p>Run the following command to install Formr with Composer.</p>
<div class="highlight"><pre><span></span><code>composer require formr/formr
</code></pre></div>
<p>Then include the <code>autoload.php</code> file and create a new form object.</p>
<div class="highlight"><pre><span></span><code><span class="k">require_once</span> <span class="s1">'vendor/autoload.php'</span><span class="p">;</span>
<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">();</span>
</code></pre></div>
<h4 id="download">Download</h4>
<p><a href="https://github.com/formr/Formr/zipball/master">Download the .zip</a> file and place the Formr folder in your project, then include the Formr class and create a new form object.</p>
<div class="highlight"><pre><span></span><code><span class="k">require_once</span> <span class="s1">'Formr/class.formr.php'</span><span class="p">;</span>
<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">();</span>
</code></pre></div>
<h2 id="frameworks">Frameworks</h2>
<p>Formr has support for the <a href="https://getbootstrap.com">Bootstrap</a> and <a href="https://bulma.io">Bulma</a> frameworks right out of the box. Just tell Formr which one you want to use when creating a new form and Formr will take care of the rest!</p>
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bulma'</span><span class="p">);</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bootstrap'</span><span class="p">);</span>
</code></pre></div>
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bootstrap4'</span><span class="p">);</span>
</code></pre></div>
<h2 id="quick-start">Quick Start</h2>
<h3 id="1-create-the-form">1. Create the Form</h3>
<p>To use Formr you will need to create a new form object. You can name it anything you like, so let's keep it simple and call it <code class="highlight"><span class="nv">$form</span></code>.</p>
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">();</span>
</code></pre></div>
<p>There are two arguments we can pass to our new form: the Wrapper, and the Switch. The Wrapper tells Formr how you want your forms to be laid out; such as with Bootstrap, Bulma, or just a simple <code><div></code> tag.</p>
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bootstrap'</span><span class="p">);</span>
</code></pre></div>
<p>Formr will automatically echo form elements and messages to the screen, and this is usually fine. However, in some instances this is not an option, such as when using a templating framework. In these cases simply pass <code>hush</code> to the Switch parameter and then manually <code class="highlight"><span class="k">echo</span></code> your elements and messages.</p>
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bootstrap'</span><span class="p">,</span> <span class="s1">'hush'</span><span class="p">);</span>
</code></pre></div>
<p>You can also omit a framework's wrapping div (e.g.; <code class="highlight"><span class="o"><</span><span class="nx">div</span> <span class="nx">class</span><span class="o">=</span><span class="s2">"form-group"</span><span class="o">></span></code>) by adding <code class="highlight"><span class="nx">nowrap</span></code> to the switch parameter.</p>
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bootstrap'</span><span class="p">,</span> <span class="s1">'nowrap'</span><span class="p">);</span>
</code></pre></div>
<p>You can use multiple switches by separating each with a comma.
<div class="highlight"><pre><span></span><code><span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bootstrap'</span><span class="p">,</span> <span class="s1">'hush, nowrap'</span><span class="p">);</span>
</code></pre></div></p>
<h3 id="2-build-the-form">2. Build the Form</h3>
<p>To build a form, simply enter your form labels as a comma separated string and Formr will build it, complete with opening and closing tags, a submit button, and email validation; plus all form values are retained upon <code class="highlight"><span class="nv">$_POST</span></code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>All field elements default to <code class="highlight"><span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span><span class="p">></span></code>, however you can easily specify another type by adding a pipe character and then the element type.</p>
</div>
<div class="admonition example">
<p class="admonition-title">Example</p>
<div class="highlight"><pre><span></span><code><span class="k">require_once</span> <span class="s1">'vendor/autoload.php'</span><span class="p">;</span>
<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bootstrap'</span><span class="p">);</span>
<span class="nv">$form</span><span class="o">-></span><span class="na">create_form</span><span class="p">(</span><span class="s1">'Name, Email, Comments|textarea'</span><span class="p">);</span>
</code></pre></div>
<p>Produces the following HTML</p>
<div class="highlight"><pre><span></span><code><span class="p"><</span><span class="nt">form</span> <span class="na">action</span><span class="o">=</span><span class="s">"/index.php"</span> <span class="na">method</span><span class="o">=</span><span class="s">"post"</span> <span class="na">accept-charset</span><span class="o">=</span><span class="s">"utf-8"</span><span class="p">></span>
<span class="p"><</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">"_name"</span> <span class="na">class</span><span class="o">=</span><span class="s">"form-group"</span><span class="p">></span>
<span class="p"><</span><span class="nt">label</span> <span class="na">class</span><span class="o">=</span><span class="s">"control-label"</span> <span class="na">for</span><span class="o">=</span><span class="s">"name"</span><span class="p">></span>
Name
<span class="p"></</span><span class="nt">label</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"name"</span> <span class="na">id</span><span class="o">=</span><span class="s">"name"</span> <span class="na">class</span><span class="o">=</span><span class="s">"form-control"</span><span class="p">></span>
<span class="p"></</span><span class="nt">div</span><span class="p">></span>
<span class="p"><</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">"_email"</span> <span class="na">class</span><span class="o">=</span><span class="s">"form-group"</span><span class="p">></span>
<span class="p"><</span><span class="nt">label</span> <span class="na">class</span><span class="o">=</span><span class="s">"control-label"</span> <span class="na">for</span><span class="o">=</span><span class="s">"email"</span><span class="p">></span>
Email
<span class="p"></</span><span class="nt">label</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"email"</span> <span class="na">name</span><span class="o">=</span><span class="s">"email"</span> <span class="na">id</span><span class="o">=</span><span class="s">"email"</span> <span class="na">class</span><span class="o">=</span><span class="s">"form-control"</span><span class="p">></span>
<span class="p"></</span><span class="nt">div</span><span class="p">></span>
<span class="p"><</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">"_comments"</span> <span class="na">class</span><span class="o">=</span><span class="s">"form-group"</span><span class="p">></span>
<span class="p"><</span><span class="nt">label</span> <span class="na">class</span><span class="o">=</span><span class="s">"control-label"</span> <span class="na">for</span><span class="o">=</span><span class="s">"comments"</span><span class="p">></span>
Comments
<span class="p"></</span><span class="nt">label</span><span class="p">></span>
<span class="p"><</span><span class="nt">textarea</span> <span class="na">name</span><span class="o">=</span><span class="s">"comments"</span> <span class="na">id</span><span class="o">=</span><span class="s">"comments"</span> <span class="na">class</span><span class="o">=</span><span class="s">"form-control"</span><span class="p">></</span><span class="nt">textarea</span><span class="p">></span>
<span class="p"></</span><span class="nt">div</span><span class="p">></span>
<span class="p"><</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">"_button"</span> <span class="na">class</span><span class="o">=</span><span class="s">"form-group"</span><span class="p">></span>
<span class="p"><</span><span class="nt">label</span> <span class="na">class</span><span class="o">=</span><span class="s">"sr-only"</span> <span class="na">for</span><span class="o">=</span><span class="s">"button"</span><span class="p">></</span><span class="nt">label</span><span class="p">></span>
<span class="p"><</span><span class="nt">button</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">name</span><span class="o">=</span><span class="s">"button"</span> <span class="na">id</span><span class="o">=</span><span class="s">"button"</span> <span class="na">class</span><span class="o">=</span><span class="s">"btn btn-primary"</span><span class="p">></span>
Submit
<span class="p"></</span><span class="nt">button</span><span class="p">></span>
<span class="p"></</span><span class="nt">div</span><span class="p">></span>
<span class="p"></</span><span class="nt">form</span><span class="p">></span>
</code></pre></div>
</div>
<h3 id="3-get-the-values">3. Get the Values</h3>
<p>After the form has been submitted we need to get its values from PHP's <code class="highlight"><span class="nv">$_POST</span></code> array. To do this, just enter the form labels into the <code class="highlight"><span class="nx">validate</span><span class="p">()</span></code> method and assign it to a variable.</p>
<div class="highlight"><pre><span></span><code><span class="nv">$data</span> <span class="o">=</span> <span class="nv">$form</span><span class="o">-></span><span class="na">validate</span><span class="p">(</span><span class="s1">'Name, Email, Comments'</span><span class="p">);</span>
</code></pre></div>
<h2 id="full-example">Full Example</h2>
<p>Copy and paste the following code into a new <code>.php</code> document and see just how fast and easy Formr really is.</p>
<div class="admonition example">
<p class="admonition-title">A Full Contact Form using Bulma</p>
<div class="highlight"><pre><span></span><code><span class="o"><?</span><span class="nx">php</span>
<span class="c1">// include Formr</span>
<span class="k">require_once</span> <span class="s1">'vendor/autoload.php'</span><span class="p">;</span>
<span class="c1">// create our form object and use Bulma as our form wrapper</span>
<span class="nv">$form</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Formr\Formr</span><span class="p">(</span><span class="s1">'bulma'</span><span class="p">);</span>
<span class="c1">// make all fields required</span>
<span class="nv">$form</span><span class="o">-></span><span class="na">required</span> <span class="o">=</span> <span class="s1">'*'</span><span class="p">;</span>
<span class="c1">// check if the form has been submitted</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$form</span><span class="o">-></span><span class="na">submitted</span><span class="p">())</span>
<span class="p">{</span>
<span class="c1">// get our form values and assign them to a variable</span>
<span class="nv">$data</span> <span class="o">=</span> <span class="nv">$form</span><span class="o">-></span><span class="na">validate</span><span class="p">(</span><span class="s1">'Name, Email, Comments'</span><span class="p">);</span>
<span class="c1">// show a success message if no errors</span>
<span class="k">if</span><span class="p">(</span><span class="nv">$form</span><span class="o">-></span><span class="na">ok</span><span class="p">())</span> <span class="p">{</span>
<span class="nv">$form</span><span class="o">-></span><span class="na">success_message</span> <span class="o">=</span> <span class="s2">"Thank you, </span><span class="si">{</span><span class="nv">$data</span><span class="p">[</span><span class="s1">'name'</span><span class="p">]</span><span class="si">}</span><span class="s2">!"</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="cp">?></span><span class="x"></span>
<span class="x"><!DOCTYPE html></span>
<span class="x"><html lang="en"></span>
<span class="x"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css"></span>
<span class="x"><body class="container"></span>
<span class="x"> </span><span class="cp"><?php</span> <span class="nv">$form</span><span class="o">-></span><span class="na">messages</span><span class="p">();</span> <span class="cp">?></span><span class="x"></span>
<span class="x"> </span><span class="cp"><?php</span> <span class="nv">$form</span><span class="o">-></span><span class="na">create_form</span><span class="p">(</span><span class="s1">'Name, Email, Comments|textarea'</span><span class="p">);</span> <span class="cp">?></span><span class="x"></span>
<span class="x"></body></span>
<span class="x"></html></span>
</code></pre></div>
</div>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<nav class="md-footer__inner md-grid" aria-label="Footer" >
<a href="methods/" class="md-footer__link md-footer__link--next" aria-label="Next: Methods" rel="next">
<div class="md-footer__title">
<div class="md-ellipsis">
<span class="md-footer__direction">
Next
</span>
Methods
</div>
</div>
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
</div>
</a>
</nav>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": ".", "features": [], "search": "assets/javascripts/workers/search.85cb4492.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version.title": "Select version"}}</script>
<script src="assets/javascripts/bundle.f758a944.min.js"></script>
</body>
</html>