• 0

Review Submission?


Question

I am making a website for this restaurant and I have a "Reviews" page. Anyone know what I would need to do where there is just a spot on that page where they can put their name, type a review, and when they are done have it go directly to the page?

Link to comment
Share on other sites

15 answers to this question

Recommended Posts

  • 0

You will need a server side language like PHP and write a script that saves the form data to a separate file. Then just include that file into the page you want to display it on. Does your server support PHP? If so, I can help you out in writing that script.

Link to comment
Share on other sites

  • 0

Ok so I have only recently been trying to learn PHP but this is what I came up with. Not really sure if it's the BEST approach but it works ok from my tests.

Based on your post, I assumed you only wanted "Name" and "Review" fields right? Because that's all I made it for, but if you have other fields let me know and I will make the adjustments.

All of the following code goes into the same page. Your Review page. Save that page as a .php file.

You will need to create a file called reviews.txt.

Also, edit the file name in the form action attribute from index.php to the name of your reviews page where this code will sit (e.g. reviews.php).

<?php

if(isset($_POST['name']) && isset($_POST['review']))
{

if (empty($_POST['name']) || empty($_POST['review'])) 
{
$status = "<span class='error'>You must fill out all of the fields.</span>";
}
else
{
$name = stripslashes($_POST['name']);
$trimmed = trim($_POST['review']);
$br = nl2br($trimmed);
$review = stripslashes($br);

$msg = "<div class='review'><strong>" . $name . "</strong> said:<br />\n" . $review . "</div>\n\n";

$fp = fopen ("reviews.txt", "a");
if ($fp) {
fwrite ($fp, $msg);
fclose ($fp);
}

$status = "<span class='success'>Success</span>";
}

}

include("reviews.txt");
echo $status;
?>

<form action="index.php" method="post">

	Name:<input type="text" name="name" />
	Review:<textarea rows="8" cols="26" name="review"></textarea>

	<input type="submit" value="Post" />

</form>

That's it. You can then style the review, success and error classes with CSS to make it look how you want.

I set up a page with it in action here: http://www.islandrobot.com/review/index.php

Let me know if you encounter any problems or need me to explain anything here.

Link to comment
Share on other sites

  • 0

Thanks. But I just realized a fatal flaw. People can easily run their own php scripts through this and hack the page. Going to fix that now and post the update.

EDIT: Here is the update that should be safe from php scripts:

<?php

if(isset($_POST['name']) && isset($_POST['review']))
{

if (empty($_POST['name']) || empty($_POST['review'])) 
{
$status = "<span class='error'>You must fill out all of the fields.</span>";
}
else
{
$name = stripslashes($_POST['name']);

$trimmed = trim($_POST['review']);
$stripped = strip_tags($trimmed);
$entities = htmlentities($stripped, ENT_QUOTES);
$br = nl2br($entities);
$review = stripslashes($br);

$msg = "<div class='review'><strong>" . $name . "</strong> said:<br />\n" . $review . "</div>\n\n";

$fp = fopen ("reviews.txt", "a");
if ($fp) {
fwrite ($fp, $msg);
fclose ($fp);
}

$status = "<span class='success'>Success</span>";
}

}

include("reviews.txt");
echo $status;
?>

<form action="index.php" method="post">

	Name:<input type="text" name="name" />
	Review:<textarea rows="8" cols="26" name="review"></textarea>

	<input type="submit" value="Post" />

</form>

Link to comment
Share on other sites

  • 0

Wow. Thanks Jordan! Ok, so say you go to tchops.net You see where it says site is under construction and what now? Well what if I wanted the review posted there instead of words? How would I make a .php file but also have html and css on it?

Link to comment
Share on other sites

  • 0

You can have php, html and css all in a php file. In fact, when looking at the code, it will be just like your regular html page but with some added php. The extension of the file however must be .php

Basically, to add the review to that page, here is the idea of what it would look like:

name: index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TCHOUPITOULAS</title>
<meta name="keywords" content="restaurant company, free website template, CSS, HTML, templatemo.com" />
<meta name="description" content="restaurant company - free website template, HTML CSS layout" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="reflection.js"></script>
</head>
<body>
<div id="templatemo_container">
  <div class="templatemo_topmenu">
    <ul>
      <li><a href="#" class="current">HOME PAGE</a></li>
      <li><a href="#">HISTORY</a></li>
      <li><a href="#">MENUS</a></li>
      <li><a href="http://www.tchops.net/pictures.html">PICTURES</a></li>
      <li><a href="#">VIDEO TOUR</a></li>
      <li><a href="#">REVIEWS</a></li>
      <li><a href="#">CONTACT</a></li>
    </ul>
  </div>
  <div id="templatemo_topsection">TCHOUPITOULAS</div>
  <div id="templatemo_headersection"><img src="images/templatemo_header_photo.jpg" class="reflect rheight20 ropacity25" alt="templatemo.com" width="806" height="166"  /></div>
  <div id="templatemo_content_section">
    <h1>Welcome To Tchoupitoulas</h1>

<?php

if(isset($_POST['name']) && isset($_POST['review']))
{

if (empty($_POST['name']) || empty($_POST['review'])) 
{
$status = "<span class='error'>You must fill out all of the fields.</span>";
}
else
{
$name = stripslashes($_POST['name']);

$trimmed = trim($_POST['review']);
$stripped = strip_tags($trimmed);
$entities = htmlentities($stripped, ENT_QUOTES);
$br = nl2br($entities);
$review = stripslashes($br);

$msg = "<div class='review'><strong>" . $name . "</strong> said:<br />\n" . $review . "</div>\n\n";

$fp = fopen ("reviews.txt", "a");
if ($fp) {
fwrite ($fp, $msg);
fclose ($fp);
}

$status = "<span class='success'>Success</span>";
}

}

include("reviews.txt");
echo $status;

?>

<form action="index.php" method="post">
        Name:<input type="text" name="name" />
        Review:<textarea rows="8" cols="26" name="review"></textarea>
        <input type="submit" value="Post" />
</form>


    <div id="templatemo_footer"><b> Copywrite ? 2010 Tchoupitoulas - Site designed by William Copus </a></u></span></div>
  </div>
</div>
</body>
</html>

All the php code is container between <?php and ?>

Link to comment
Share on other sites

  • 0

Yep. The reviews.txt file will contain all of the reviews. Just delete the ones you don't want. Each review will be separated by one blank line.

Link to comment
Share on other sites

  • 0

Yep. The reviews.txt file will contain all of the reviews. Just delete the ones you don't want. Each review will be separated by one blank line.

Works awesome. Just one question. If you go to www.tchops.net/reviews.php You see how it's

Name: ------

----

----

----

----

Review:----

Is there any way I can make it where the review is on the top right of the box like with name?

Link to comment
Share on other sites

  • 0

Ok I understand now.

Do this for your name and review fields.

	&lt;label for="lname"&gt;Name:&lt;input type="text" name="name" id="lname" /&gt;&lt;/label&gt;
	&lt;label for="lreview"&gt;&lt;span&gt;Review:&lt;/span&gt;&lt;textarea rows="8" cols="26" name="review" id="lreview"&gt;&lt;/textarea&gt;&lt;/label&gt;

And add this to your css:

label {
	display: block;
}

label span {
	vertical-align: top;
}

Link to comment
Share on other sites

  • 0

Unless I am doing something wrong, that didn't work. But one more question. Is there a way the code could be altered to make it where it doesn't look so cluttered? Like, if you go to the page and you see the two submissions on there, you see how it looks like one? Could I add a line between each one or something?

Link to comment
Share on other sites

  • 0

Did you add the CSS? I am not seeing what I posted in your stylesheet.

And to space out each review, you can style the "review" class. So add something like this to your CSS:

.review {
	margin-bottom: 30px;
}

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.