If we want users to be able to post their own greetings, we need a way to process information submitted by the user with a web form. PHP makes processing form data easy.
Handling Web Forms
Replace the contents of
helloworld/helloworld.php
with the following:
Reload the page to see the form, then try submitting a message.
When the form is submitted, the application receives a request using the HTTP POST method (
method="post"
) and PHP makes POSTed form variables available using the
$_POST
superglobal.
Let's take a closer look at how the form is processed:
Before displaying the message (stored in
<textarea name="content"
), the application checks to see if is present in the
$_POST
superglobal. If it is then special HTML characters in the message (like "<") are replaced with their corresponding HTML entities (like <) using the
htmlspecialchars
function.
Next...
Every web application returns dynamically generated HTML from the application code, via templates or some other mechanism. Most web applications also need to serve static content, such as images, CSS stylesheets, or JavaScript files. For efficiency, App Engine treats static files differently from application source and data files. You can use App Engine's static files feature to serve a CSS stylesheet for this application.