This repository was archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdemo.php
More file actions
71 lines (57 loc) · 2.39 KB
/
demo.php
File metadata and controls
71 lines (57 loc) · 2.39 KB
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
<?php
/**
* HTML5 Form Class
*
* A simple form class to make building / validating forms easier.
*
* @author Mike Rogers <mike.r@fullondesign.co.uk>
* @since 21/08/2011
*/
include('func/functions.func.php');
include('class/notices.class.php');
include('class/form.class.php');
// Set up the classes.
$notices = new notices();
$myForm = new mr_form();
// Add some fields to the form.
// This is a standard text input field, with a label of "Your Name"
$myForm->setInputField(array('name'=>'your-name', 'required'=>true), 'Your Name', true);
// This is an email field.
$myForm->setInputField(array('name'=>'emails[]', 'type'=>'email', 'placeholder'=>'you@mail.com'), 'Your Email 1 (Optional)', true);
$myForm->setInputField(array('name'=>'emails[]', 'type'=>'email', 'placeholder'=>'you@mail.com'), 'Your Email 2 (Optional)', true);
// This is a select field.
$options = $myForm->setSelectField(array('name'=>'your-gender', 'value'=>'female'), 'Your Gender', TRUE);
// You can add options like this:
$options->addOption('male', 'Male');
// Or if you don't want to create a new variable, like this:
$myForm->fields['your-gender']->addOption('female', 'Female');
$myForm->fields['your-gender']->addOption('other', 'Other');
$radio = $myForm->setRadioField(array('name'=>'type_new', 'required'=>false), 'New or Existing test', true);
$radio->addOption('1', 'This is a new test that we still have to do');
$radio->addOption('2', 'This is a test we already did but want to document insights');
$myForm->setTextArea(array('name'=>'your-comments'), 'Comments', true);
$myForm->setInputField(array('name'=>'submit', 'value'=>'Submit', 'type'=>'Submit'));
$myForm->setHtmlSnippet('Thanks for looking at my form!');
if($myForm->isSent() && $myForm->validInput()){
// It's been sent and it's valid. Do something with the data.
// Use $_POST['name'] to access data, but you can also use $myForm->getInputValue('name')
$notices->add('The form has worked!');
}
?>
<html lang="en" class="no-js">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>PHP - HTML5 Form Class</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css?v=1">
</head>
<body>
<h1>PHP - HTML5 Form Class</h1>
<?php
if(is_array($notices->notices)){ // If there is an notice to display.
$notices->display();
}
$myForm->display();
?>
</body>
</html>