muleman
12-03-2005, 01:38 PM
can any 1 please tel me how to create a comment box, form or message box where you can in put a message and press submit and the message will be put into another cell on the same page?
any help would be great can't find out how to do it. i can send it to my email but i cant find out how to send to the same page into a certain page.
harmor
12-03-2005, 08:55 PM
Part 1
First you create a form.
Save this as comment.html
<form action="process.php" method="post">
Name: <input type="text" name="name" /><br />
URL <input type="text" name="url" /><br /><br />
-Comment-
<textarea name="comment" cols="55" rows="14"><textarea><br />
<input type="submit" value="Submit" />
</form>
I'll break this down
<form action="process.php" method="post">
The "action" attribute is where it sends the page after you press "Submit"
The page will usually end with a ".php", ".cgi", or ".pl", most likely it'll me a php extension.
In "process.php" is the coding to retrieve and store the users' input.
Name: <input type="text" name="name" /><br />
The "input type" what kind've box it'll be. In this case this will be a single line box.
The "name" attribute gives the user's input an identity from the other fields in the form (URL, and comments).
On "process.php" you will have "$_POST['name']". This gets the user's data and stores it.
URL <input type="text" name="url" /><br /><br />
This is similiar to the one above but now the name attribute is using "url" to identify the user's data.
so in "process.php" you would use "$_POST['url']" to store the information.
<textarea name="comment" cols="55" rows="14"><textarea><br />
This is a textarea, a place to type multiple lines of text.
Hopefully we have established what the name attribute is used for but if not then that's ok. (I don't want to be accused as being mean).
On "process.php" to store the information you would use "$_POST['comment']"
The "cols" attribute controls the height of the text area and "rows" controls the wwidth
<input type="submit" value="Submit" />
This is the submit button, There's nothing to really say about it.
The value attribute will show the text on the button.
So in this case you will see "Submit" on the button.
</form>
This just ends the form, that's all.
harmor
12-04-2005, 01:32 AM
Now create a file named process.php
I don't have time to explain what is happening below.
[COLOR="SeaGreen"]<?php
function postit($str)
{
$str = htmlentities($str);
$str = str_replace ("\n", "<br />", $str);
return $str;
}
$name = postit($_POST['name']);
$url = postit($_POST['url']);
$comment = postit($_POST['comment']);
$filename = 'comments.txt';
$somecontent = "Name: $name\n
Url: $url\n
Comment\n
$comment\n\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
muleman
12-04-2005, 04:12 PM
thanks for that il go try it in a bit, do you just paste it into the code section in dreamweaver,
when you say file you mean a new page or a new file containg a page?
can i ask before i do it will i be able to put it into a layer containing a div? which is only 1/4 size of the page?
i can send you the page source if it would be easyer lol.
harmor
12-04-2005, 04:38 PM
It wouldn't let me post the whole php thing so here's the coding:
Note from Admin: Please do not post links to your own site.
Create a file named comments.txt and chmod it to 777
Upload all three file to the same directory/folder.
I want you try it yourself because you'll get a greater satifaction.
Note that the code can only write, it cannot read the contents.
Report back when you have successfully got it done.
xxhillary
12-04-2005, 07:05 PM
http://chasebadkids.net/commentbox.htm
but its for myspace. i dunt no if it'll work
harmor
12-04-2005, 10:15 PM
I'm sorry muleman but apparently I can't post a link to the full code if it's on my site.
Contact me on MSN and I'll help.
(That is if I'm not allowed to offer help through msn)
J-man91
12-07-2005, 07:51 PM
Hm, I'd like to try this out, but I don't think you have the full coding here. Is there a way I could get it?