Last active
December 19, 2015 01:29
-
-
Save thejhh/5875888 to your computer and use it in GitHub Desktop.
Example code for our new UI library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <html> | |
| <head> | |
| <title>Example Form Application</title> | |
| </head> | |
| <body> | |
| <h1>Example Form Application</h1> | |
| <div class="form" data-action="resource.php"></div> | |
| <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
| <script src="http://dev.jhh.me/lib-jquery-nor-form.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Setup $_SESSION | |
| session_start(); | |
| if(!isset($_SESSION['res'])) { | |
| $_SESSION['res'] = array( | |
| 'name' => '', | |
| 'email' => '', | |
| 'info' => '' | |
| ); | |
| } | |
| // Check method | |
| $method = strtolower($_SERVER['REQUEST_METHOD']); | |
| if(isset($_POST['_action'])) { | |
| $method = strtolower($_POST['_action']); | |
| } | |
| // Handle GET requests | |
| if($method === "get") { | |
| echo json_encode($_SESSION['res']) . "\n"; | |
| exit(); | |
| } | |
| // Handle POST requests | |
| if($method === "post") { | |
| foreach($_POST as $key => $value) { | |
| $_SESSION['res'][$key] = $value; | |
| } | |
| exit(); | |
| } | |
| // Handle PUT requests | |
| if($method === "post") { | |
| $_SESSION['res'] = clone $_POST; | |
| exit(); | |
| } | |
| // Handle DELETE requests | |
| if($method === "delete") { | |
| unset($_SESSION['res']); | |
| exit(); | |
| } | |
| // Output error | |
| header(':', true, 500); | |
| header('Content-Type: application/json'); | |
| echo json_encode(array('type'=>'error', 'msg'=>'Internal Server Error')) . "\n"; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment