Hello,
I ahve built a comment form with some peoples help on this forum. Someone then suggested that guests may not want there email address to be visible on the site so i decided to add a checkbox to ask them. If ticked the address could be displayed. If unchecked then it couldn't. I want the box to be checked by default. I have tried it but something is always wrong and I cannot get that part to work. Below is the code i am using. Can anyone try to figure out where I am going wrong?
PHP Code:<?php
$form_name = null;
$form_email = null;
$form_comment = null;
$form_rating = null;
$form_emailshow = null;
$error="";
?>
<?php
if (isset($_POST['submit'])) { //If form HAS been submitted
if (!empty($_POST['name'])) {
$form_name = $_POST['name'];
$form_name = htmlentities($form_name);
$form_name = mysql_real_escape_string($form_name);
}else{
$form_name = null;
$error.="Enter your name<br />";
}
if (!empty($_POST['email'])) {
$form_email = $_POST['email'];
$form_email = htmlentities($form_email);
$form_email = mysql_real_escape_string($form_email);
}else{
$form_email = null;
$error.="Enter your email<br />";
}
if (!empty($_POST['rating'])) {
$form_rating = $_POST['rating'];
$form_rating = htmlentities($form_rating);
$form_rating = mysql_real_escape_string($form_rating);
}else{
$form_rating = null;
$error.="Choose your rating<br />";
}
if (!empty($_POST['comment'])) {
$form_comment = $_POST['comment'];
$form_comment = htmlentities($form_comment);
$form_comment = mysql_real_escape_string($form_comment);
}else{
$form_comments = null;
$error.="Enter your comment<br />";
}
if ($_POST['emailshow'] = 1) {
$form_emailshow = $_POST['emailshow'];
$form_emailshow = htmlentities($form_emailshow);
$form_emailshow = mysql_real_escape_string($form_emailshow);
$form_emailshow = 1;
} else {
$form_emailshow = 0;
}
$form_auth = 0;
$form_auth = htmlentities($form_auth);
$form_auth = mysql_real_escape_string($form_auth);
$form_rideid = $rideid;
$form_rideid = htmlentities($form_rideid);
$form_rideid = mysql_real_escape_string($form_rideid);
if (!empty($error)) {
echo '<p style="color:#ff0000; class="center">' . $error . '</p>';
require('comment_form.inc.php');
} else {
//Add comment into database and send e-mail
$addcomment = mysql_query("INSERT INTO atm_ridecomments (comment_name, comment_email, comment_rating, comment_comment, comment_auth, comment_rideid, comment_emailshow) VALUES('$form_name', '$form_email', '$form_rating', '$form_comment', '$form_auth', '$form_rideid', '$form_emailshow')") or die(mysql_error());
if ($addcomment) {
echo '<p>Comment added successfully.</p>';
}else{
echo '<p>Comment failed.</p>';
}
$subject = 'Thanks for posting a comment.';
$message = 'Hello,/nThanks for submitting a comment on Alton Towers Mania - www.atmania.com /n/nYour comment will be authorised and then posted up on the site./n/nThanks Again/nAlton Towers Mania';
if (@mail($form_email, $subject, $message)) {
echo('<p>Confirmation E-Mail sent.</p>');
} else {
echo('<p>Confirmation E-Mail failed to send.</p>');
}
}
}else{ //If form HAS NOT been submitted then show form
?>
<?php
require('comment_form.inc.php');
?>
<?php
}
?>
The form itself which is included in the above code at certain points:
ThanksPHP Code:<div>
<form action="<?php $_SERVER['PHP_SELF']; ?>" name="addcomment" method="post">
<div class="input_div"><label for="name">Name:</label><input class="form" id="name" type="text" name="name" value="<?php echo $form_name; ?>" /></div><br />
<div class="input_div"><label for="email">E-Mail Address:</label><input class="form" id="email" type="text" name="email" value="<?php echo $form_email; ?>" /></div>
<br />
<div class="input_div"><label for="emailshow">Show E-Mail on site?:</label><input <?php if ($form_emailshow == '0') { echo '';}else{echo 'checked="checked"';} ?> class="form" id="emailshow" type="checkbox" name="emailshow" /></div>
<br />
<div class="input_div"><label for="rating">Rating:</label>
<table style="margin-left:105px;" width="60%" border="0">
<tr>
<td>
<input <?php if ($form_rating == '1star') { echo 'checked="checked"';}else{echo '';} ?> class="form" type="radio" name="rating" VALUE="1star" name="1star"></td><td><img src="img/votestars/1star.gif" alt="1 Star Rating" />
</td></tr><tr><td>
<input <?php if ($form_rating == '2star') { echo 'checked="checked"';}else{echo '';} ?> class="form" type="radio" name="rating" VALUE="2star" name="2star"></td><td><img src="img/votestars/2star.gif" alt="2 Star Rating" />
</td></tr><tr><td>
<input <?php if ($form_rating == '3star') { echo 'checked="checked"';}else{echo '';} ?> class="form" type="radio" name="rating" VALUE="3star" name="3star"></td><td><img src="img/votestars/3star.gif" alt="3 Star Rating" />
</td></tr><tr><td>
<input <?php if ($form_rating == '4star') { echo 'checked="checked"';}else{echo '';} ?> class="form" type="radio" name="rating" VALUE="4star" name="4star"></td><td><img src="img/votestars/4star.gif" alt="4 Star Rating" />
</td></tr><tr><td>
<input <?php if ($form_rating == '5star') { echo 'checked="checked"';}else{echo '';} ?> class="form" type="radio" name="rating" VALUE="5star" name="5star"></td><td><img src="img/votestars/5star.gif" alt="5 Star Rating" />
</td></tr></table>
</div><br />
<div class="input_div"><label for="comment">Comments:</label><textarea cols="22" rows="5" class="form" id="comment" name="comment"><?php echo $form_comment ?></textarea><br /><br />
</div>
<br /><br />
<div class="center">
<input type="submit" value="Submit Comment" name="submit" />
<input type="reset" value="Reset Form" name="reset" />
</div>
</form>
</div>
Neil






/label><input <?php echo $checked; ?> class="form" id="emailshow" type="checkbox" name="emailshow" /></div>


Bookmarks