Interestingly enough, I got everything to work, except the comments section. I'm forwarding the link to my blog page:
http://www.artispot.com/main/blog.php
If you click on any of the blog entries, it'll take you to the post page, where I'm having an issue.
As you can see, validation works just fine. However, when I try to submit a new post, the button disappears and nothing happens.
I'm posting some code so you can see how I'm trying to acheive it. Form code first. I've altered the original to allow ajax:
<form id="commentform" method="post" action="" class="ajax_form">
<div class="personal_data"><?php if (!isset($errorC) || $errorC == true){ ?>
<p class="<?php if (isset($the_nameclass)) echo $the_nameclass; ?>" ><label for="author"><small>Name (required)</small></label><input type="text" tabindex="1" size="22" value='<?php if (isset($the_name)) { echo $the_name; } else { echo "Name"; } ?>' id="author" class="text_input is_name" name="author"/>
</p>
<p class="<?php if (isset($the_emailclass)) echo $the_emailclass; ?>"><label for="email"><small>Mail (will not be published) (required)</small></label><input type="text" tabindex="2" size="22" value='<?php if (isset($the_email)) { echo $the_email; } else { echo "Email"; } ?>' id="email" class="text_input is_email" name="email"/>
</p>
<p><label for="url"><small>Website</small></label><input type="text" tabindex="3" size="22"value="<?php if (isset($the_website)) { echo $the_website; } else { echo "Website URL"; }?>" id="url" class="text_input" name="url"/>
</p>
</div>
<div class="message_data">
<p class="<?php if (isset($the_messageclass)) echo $the_messageclass; ?>"><textarea style="width: 589px !important" tabindex="4" class="text_area is_empty" rows="10" cols="100%" id="comment" name="comment"><?php if (isset($the_message)) echo $the_message ?></textarea></p>
</div>
<input type="hidden" id="postID" name="postID" value="<?php echo $postID; ?>" />
<p><input type="submit" value="Submit" tabindex="5" id="submit" class="button" name="submit"/>
<?php } else { ?>
<?php } ?>
</p>
</form>
Now for the actual submission code. I've just re-used the Contact.php code and changed some things:
if(isset($_POST['Submit']) || isset($_POST['ajax'])){
$errorC = false;
$postID = $_POST['postID'];
$the_name = $_POST['author'];
$the_email = $_POST['email'];
date_default_timezone_set('America/New_York');
$time = time();
function makeClickableWebsite($the_website) {
$the_website = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1', $the_website);
$the_website = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1\\2', $the_website);
$the_website = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'\\1', $the_website);
return $the_website;
}
$the_website = makeClickableWebsite(stripslashes($_POST['website']));
function makeClickableLinks($the_message) {
$the_message = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1', $the_message);
$the_message = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1\\2', $the_message);
$the_message = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'\\1', $the_message);
return $the_message;
}
$the_message = makeClickableLinks(str_replace(array("\\r\\n", "\\r", "\\n"), "
", stripslashes($_POST['comment'])));
if(!checkmymail($the_email))
{
$errorC = true;
$the_emailclass = "error";
}else{
$the_emailclass = "valid";
}
if($the_name == "" || $the_name == "Name")
{
$errorC = true;
$the_nameclass = "error";
}else{
$the_nameclass = "valid";
}
if($the_message == "")
{
$errorC = true;
$the_messageclass = "error";
}else{
$the_messageclass = "valid";
}
if($errorC == false)
{
$newcomment = mysql_query("INSERT into $table24 (postID, commentDate, author, email, website, comment) VALUES ('$postID', '$time', '$the_name', '$the_email', '$the_website', '$message')") or die (mysql_error());
if(isset($_POST['ajax'])){
echo"<p>Thank you for your comment!</p>";
}
getcount($table24, $postID);
getcomments($table24, $postID);
}
}
function checkmymail($the_email){
$email_flag=preg_match("!^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$!",$the_email);
return $email_flag;
}
I'm calling in the script using this code:
if(isset($_POST['Submit']))
{
include('../phpf/submitcomment.php');
}
Same as on the contact page. Calling in the script once the form is set. Can you help?