source: trunk/prototype/library/tonic/examples/htmlform/htmlform.php @ 6528

Revision 6528, 1.4 KB checked in by gustavo, 12 years ago (diff)

Ticket #2766 - Merge do branch das novas funcionalidaes para o trunk

  • Property svn:executable set to *
Line 
1<?php
2
3/**
4 * Display and process a HTML form via a HTTP POST request
5 *
6 * This example outputs a simple HTML form and gathers the POSTed data
7 *
8 * @namespace Tonic\Examples\HTMLForm
9 * @uri /htmlform
10 */
11class HTMLForm extends Resource {
12   
13    /**
14     * Handle a GET request for this resource
15     * @param Request request
16     * @return Response
17     */
18    function get($request, $name) {
19       
20        $response = new Response($request);
21       
22        if ($name) {
23            $welcome = "<p>Hello $name.</p>".
24                "<p>Raw POST data:</p>".
25                "<blockquote>$request->data</blockquote>";
26        } else {
27            $welcome = "<p>Enter your name.</p>";
28        }
29       
30        $response->addHeader('Content-type', 'text/html');
31        $response->body = <<<EOF
32<!DOCTYPE html>
33<html>
34    <body>
35        <form action="htmlform" method="post">
36            <label>Name: <input type="text" name="name"></label>
37            <input type="submit">
38        </form>
39        $welcome
40    </body>
41</html>
42EOF;
43       
44        return $response;
45       
46    }
47   
48    /**
49     * Handle a POST request for this resource
50     * @param Request request
51     * @return Response
52     */
53    function post($request) {
54       
55        if (isset($_POST['name'])) {
56            $name = htmlspecialchars($_POST['name']);
57        } else {
58            $name = '';
59        }
60       
61        return $this->get($request, $name);
62       
63    }
64   
65}
66
Note: See TracBrowser for help on using the repository browser.