Welcome to PHPMule.com
A blog site which I am posting to during my learning of the popular programming language PHP. Feel free to leave comments!
-
Making A Comments Form
I have been experimenting with PHP over the last couple hours trying to design a comments form. By the way I am the newbee of newbies at this stuff so it takes a while to know the concepts!
Well here goes:
<html>
<head>
<title>Comment Form - Submit your comments!</title>
</head>
<body>
<form action=”processcomment.php” method=”post”>
<table border=”0″>
<tr>
<td>First Name: </td>
<td align=”left”><input type=”text” name=”firstname” size =”20″ maxlength=”20″ /></td>
</tr>
<tr>
<td>Email Address: </td>
<td align=”left”><input type=”text” name=”emailaddress” size =”30″ maxlength=”30″ /></td>
</tr>
<tr>
<td>Comments: </td>
<td align=”left”><input type=”text” name =”comments” size =”100″ maxlength=”100″ /></td>
</tr>
<tr>
<td colspan=”2″ align =”center”><input type=”submit” value=”Submit Comment” /></td>
</tr>
</table>
</form></body>
</html>This is the comments form that I created. (Using HTML, PHP Script to follow) This will be a basic comments form to take the first name, email address and obviously their comments. You will notice that the form’s action contains the file name “processcomments.php”. This is the file that get’s processed once the submit button on the form is pressed.
The following file contains three global variables. (e.g. $_POST['firstname'] ) You might notice that the value your visitor sent when they entered their ‘firstname’ will now be the variable and therefore can be controlled in the processcomments.php script. Same goes with their emailaddress and comments.
Here is the processcomments.php file:
<?php
$firstname = $_POST['firstname'];
$emailaddress = $_POST['emailaddress'];
$comments = $_POST['comments'];
?><html>
<head>
<title>Process Comment</title>
</head><body>
<?php
echo “<p>Following comment sent: </p><br />”;
echo “First Name: ” . $firstname . “<br />”;
echo “Email Address: ” . $emailaddress . “<br />”;
echo “Comments: ” . $comments . “<br />”;
?></body>
</html>
When you press the ‘Submit Comment’ button this file is opened and will output this to the browser:
Following comment sent:
First Name: Nathan
Email Address: admin@phpmule.com
Comments: My very first comments box!Although it say’s it’s sent, it’s actually not until we add a bit more code… Will add how to do this in the next blog post!
(Post created on Monday, April 6th 09 at 21:55)
-
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||
Archives
Recent Articles
- PHP - Rounding Off Numbers
- PHP - Single vs Double Quotation Marks
- PHP - Loading Files Into Your PHP Script By Using require() and include()
- PHP - Replacing Strings With Other Strings
- PHP - Finding Strings Within Strings
- PHP - Using strlen() To Test String Length
- PHP - Using The explode() Function
- PHP - Changing The String Case
- PHP - The nl2br() Function
- PHP - Trimming Strings
Links
Categories
- PHP (22)
- Uncategorized (1)


