Difference between revisions of "Web forms and PHP"
From Wiki @ Karl Jones dot com
Karl Jones (Talk | contribs) (Created page with "This article discusses web forms and PHP. == Example == The examples below are based on [http://php.net/manual/en/tutorial.forms.php this page @ php.net]...") |
Karl Jones (Talk | contribs) (→See also) |
||
Line 34: | Line 34: | ||
== See also == | == See also == | ||
− | * [[Form (HTML)]] | + | * [[Form (HTML element)]] |
== External links == | == External links == |
Revision as of 13:47, 14 September 2016
This article discusses web forms and PHP.
Example
The examples below are based on this page @ php.net.
Create an HTML page (call it formpage.html
, for convenience) containing this web form:
<form action="action.php" method="post"> <p>Your name: <input type="text" name="name" /></p> <p>Your age: <input type="text" name="age" /></p> <p><input type="submit" /></p> </form>
Note that the form's action attribute is set to action.php
. When the user submits the form, the form data will be sent to a PHP page named action.php
(in the same folder as the web form page). The file name action.php
is arbitrary -- any valid file name will work.
The action.php
page contains the following:
Hi <?php echo htmlspecialchars($_POST['name']); ?>. You are <?php echo (int)$_POST['age']; ?> years old.
When the user fills out and the submits the web form, the action.php
page will display something like this:
Hi Joe. You are 22 years old.
Note that both formpage.html
and action.php
should contain complete and valid HTML. The above examples show only excerpts, not the complete HTML.