NameSilo

How to make a comment form in PHP?

Spaceship Spaceship
Watch

shilpamg

Established Member
Impact
0
Please anybody tell me how will i prepare a comment form in PHP?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
hello anybody please reply me.
 
0
•••
0
•••
It's easy. Make a form with HTML then set its action to a PHP page that processes it. Look into the PHP mail() function (www.php.net/mail) and look into converting $_POST array variables to local ones. This lets you access what the user typed.

If you have any more questions feel free to respond.
 
0
•••
mholt said:
Look into the PHP mail() function (www.php.net/mail) and look into converting $_POST array variables to local ones.

What are you going to use the mail() function in a comment form for?
 
0
•••
Agar said:
What are you going to use the mail() function in a comment form for?


The simplest comment form takes the comment from the form and emails it to a specified email. Hence, the need for using the mail() function arises.
 
0
•••
nasaboy007 said:
The simplest comment form takes the comment from the form and emails it to a specified email. Hence, the need for using the mail() function arises.

Hum ok, didn't think any of those comment forms existed but well. I would've stored the comments in a database or equivalent.
 
0
•••
Agar said:
Hum ok, didn't think any of those comment forms existed but well. I would've stored the comments in a database or equivalent.
You could, but it is much easier for a simple form to just email it :) Generally you'll only need a database if you want to manipulate sets of data over a period of extended time.
 
0
•••
mholt said:
You could, but it is much easier for a simple form to just email it :) Generally you'll only need a database if you want to manipulate sets of data over a period of extended time.

Maybe I misread OP, I thought he was supposed to make a comment form for blog posts or something similiar
 
0
•••
Please anybody tell me how will i prepare a comment form in PHP?

I think you misread, i don't see the word "blog" or anythign of the likes in there lol XD.
 
0
•••
nasaboy007 said:
I think you misread, i don't see the word "blog" or anythign of the likes in there lol XD.
True; the OP isn't very specific.... the first thing that came to my head was like a "contact" form; he didn't specify having the comments posted on his website.

In that case, a file or database would be easiest.
 
0
•••
0
•••
PHP Comment Script
The script can be included in your website pages and allows your visitors to leave comments. The comments can be edited and deleted in the admin area.
Comment Script Features

* Visitors can enter a name, e-mail, homepage, comment title and comment text
* Comment script can be included in existing web pages
* E-Mail notification of new comments
* Comment moderation
* CAPTCHA feature to prevent spam
* Akismet
* Content Blocker
* IP Blocker
* Flood protection
* Bad Word Filter
* Smilies/Emoticons
* Admin area for editing and deleting comments
* Completely template driven
* Installation routine


define('C5T_ROOT', '../');


// Settings
$c5t_detail_template = 'admin_comment.tpl.html';

define('C5T_ALTERNATIVE_TEMPLATE', 'admin');
define('C5T_LOGIN_LEVEL', 1);



// Include
require C5T_ROOT . 'include/core.inc.php';
require 'comment.class.inc.php';


// Start output handling
$out = new c5t_output($c5t_detail_template);


// Start comment handling
$comment = new c5t_comment;


// Handle and validate form
require_once 'HTML/QuickForm.php';


// Start form handler
$c5t_form = new HTML_QuickForm('form', 'POST', getenv('REQUEST_URI'));


// Get form configuration
require 'comment_form.inc.php';


// Get identifier data from table
require 'identifier.class.inc.php';
$identifier = new c5t_identifier;
if ($identifier_id = c5t_gpc_vars('i')
and $identifier_data = $identifier->get($identifier_id)) {
$out->assign('identifier_data', $identifier_data);
}


// Validate form
$message = array();
$show_form = 'yes';
if ($comment_id = c5t_gpc_vars('c')
and $c5t_form->validate()) {
$comment->update($comment_id);
// $show_form = 'no';
// $c5t_form->freeze();
$c5t['message'][] = $text['txt_update_data_successful'];
} else {
if (sizeof($c5t['_post']) > 0) {
$c5t['message'][] = $text['txt_fill_out_required'];
}
}
$out->assign('show_form', $show_form);


// Get comment data
if ($comment_id = c5t_gpc_vars('c')
and $comment_data = $comment->get($comment_id)) {
array_walk($comment_data, 'c5t_clean_output');
$defaults = array(
'comment_id'=> $comment_data['comment_id'],
'name' => $comment_data['comment_author_name'],
'email' => $comment_data['comment_author_email'],
'homepage' => $comment_data['comment_author_homepage'],
'title' => $comment_data['comment_title'],
'comment' => $comment_data['comment_text']
);
$c5t_form->setDefaults($defaults);
$out->assign('comment_data', $comment_data);
}


require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($out->get_object, true);

$c5t_form->accept($renderer);


// Assign array with form data
$out->assign('form', $renderer->toArray());


// Output
$out->finish();





?>
 
0
•••
<form action="sendmail.php" method="POST">
<b>Your name :</b> <input type="text" name="name"><br>
<b>Your e-mail :</b> <input type="text" name="email"><br>
<b>Message</b><br><textarea name="message"></textarea>
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>


<?php
/*Here we are going to declare the variables*/
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\\n\\nFEEDBACK: $message";
$recipient = "[email protected]";
$subject = "Contact Form";
$mailheader = "From: $email\\r\\n";
$mailheader .= "Reply-To: $email\\r\\n";
$mailheader .= "MIME-Version: 1.0\\r\\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Failure!");
echo "Thank You!";
?>
 
0
•••

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back