Peep in my mind

Tag Archive | "forms"

Tags: , , ,

Creating Forms with HTML and PHP

Posted on 10 June 2009 by admin

php101

Forms

Code to generate forms goes between <form> data </form> tags.  In the opening form tag also contains an action attribute.  This indicates which page the form data should submit.
<form action=”submit.php”>

There are two methods of transmitting data from the form to the handling script. They are GET and POST.  The GET method sends all the gathered information along as part of the url. The Post method sends the data invisibly.

Example of the GET method.

http://www.blah.com/page.php?var=value&blah…

Example of the POST method.

http://www.blah.com/page.php

Notes to keep in mind about GET method.

  • GET method is limited amount of data that can be transferred.
  • Data can be view publicly which may cause security risk.
  • A page created by GET method can be bookmarked.
  • GET pages can be reloaded POST pages will have a confirmation box

To used the form data submitted users need to use predefined variables.  They are $_GET and $_POST they are used based on which type of method is picked when generating the form.  If the method was post then use $_POST if the method was GET then use $_GET.  Also the variable must be typed with all caps cause it is case sensitive.

Sample code form.html

<body>
<form action=”display_form.php” method=”post”>
<p>Comments: <textarea name=”comments” rows=”3″ cols=”30″></textarea></p>
<input type=”submit” name=”submit” value=”Send Comment” />
</form>
</body>

Sample code display_form.php

<body>
<?php
$comments = $_POST['comments'];
print “<p>Thank you for the comment <br />$comments</p>”;
?>
</body>

These notes are from PHP for the World Wide Web, Third Edition (Visual QuickStart Guide) written by Larry Ullman. In order to make sense of my notes you should pruchase the PHP book its very well written and easy to follow.

Comments (0)

Advertise Here
Advertise Here

RELATED SITES