Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 146 lines (126 sloc) 3.912 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 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
<?php
/*
The OnceForm - Write once HTML5 forms processing for PHP.

Copyright (C) 2012 adcSTUDIO LLC

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

include '../OnceForm.php';

$form1 = new OnceForm();

// build the form programatically by creating HTML in a string
// using whatever method or library you like.
$html = '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
$html .= '<p><input type="email" name="user_email" placeholder="Enter your email address"></p>';

$html .= ' <p>
<input type="email" name="designer_stuff" required placeholder="Enter your email address">
</p>
<p>
<input name="ckBox1" type="checkbox" id="ckBox1" value="test" required>
<label for="ckBox1">test 1</label>
<input name="ckBox2" type="checkbox" id="ckBox2" value="test">
<label for="ckBox2">test 2</label>
</p>
<p>
<input type="radio" name="rdSet" id="radio1" value="radio1">
<label for="radio1">test A</label>
<input type="radio" name="rdSet" id="radio2" value="radio2">
<label for="radio2">test B</label>
</p>
<p>
<label for="selectTest">Select Something</label>
<select name="selectTest" id="selectTest">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</p>
<p>
<input type="submit" value="Go!">
</p>';

$html .= '</form>';

// slightly more boilerplate than the fully automatic way
$form1->parse_form( $html );
$form1->check_request();

if ( $form1->is_request() )
{
$form1->validate();

if ( $form1->isValid )
{
// Do something with the data
$form1->data;
}
else {
// probably don't have to do anything!!
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>

<body>
<table>
<tr>
<td valign="top"><p>This is a basic HTML5 form with validation.</p></td>
<td valign="top"><p>This is the same form with no validation.<br>
(Use this to sidestep client side HTML5 validation, and<br>
submit invalid data to the server to demo the OnceForm.)</p></td>
</tr>

<tr><td>
<?php echo $form1 ?>
</td>
<td>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="form1">

<p>
<input type="text" name="user_email" placeholder="Enter your email address">
</p>
<p>
<input type="text" name="designer_stuff" placeholder="Enter your email address">
</p>
<p>
<input name="ckBox1" type="checkbox" id="ckBox1" value="test">
<label for="ckBox1">test 1</label>
<input name="ckBox2" type="checkbox" id="ckBox2" value="test">
<label for="ckBox2">test 2</label>
</p>
<p>
<input type="radio" name="rdSet" id="radio1" value="radio1">
<label for="radio1">test A</label>
<input type="radio" name="rdSet" id="radio2" value="radio2">
<label for="radio2">test B</label>
</p>
<p>
<label for="selectTest">Select Something</label>
<select name="selectTest" id="selectTest">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</p>
<p>
<input type="submit" value="Go!">
</p>
</form>
</td>
</tr>
</table>

<pre>
isRequest: <?php var_dump( $form1->is_request() ) ?>
isValid: <?php var_dump( $form1->isValid ) ?>

<?php print_r( $form1->validators ) ?>

<?php print_r( $form1->errors ) ?>

<?php print_r( $_POST ) ?>
</pre>

</body>
</html>
Something went wrong with that request. Please try again.