Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: display a message when we are writing a comment "comment has been sent and awai  (Read 4090 times)

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663

I am confused and don't know the reasoning as to why you would want a static HTML file to show the comment sent/approval/error message.  Doesn't make sense unless you want to ajax it in or have a popup....

Seems the code which you gave us.. i think is just for refreshe pages(back to content).
The code I noted was in the default snews.php file for the section you were looking for - replying to the first post only.  

Quote
as i said there is no relation betwen snews.php file and that page.
if those pages are linked together .. yes we can use the code in that time.. but now aren't .. and what i'am trying to do in my snews CMS is to hide the page which show us sentence (comment sent) i want directly to show page ( comment_sent.html) when the visitor commented at the article.
You can link a static page to a dynamic page using ajax. Here is a (sortof) untested guess to the solution:

Code: (snews.php comments section) [Select]
// Snippet of the comments function

// echo '<h2>'.$commentStatus.'</h2>';
// if (!empty($commentReason)) {echo '<p>'.$commentReason.'</p>';}
$postCat = clean(cleanXSS($_POST['category']));
$postArt = clean(cleanXSS($_POST['article']));
$back_link = db('website').$postCat.'/'.$postArt.'/';
# 2. 1.6.0 - new string replaces 5 strings in 1.5.31, refreshes content.
// echo '<meta http-equiv="refresh" content="1; url='.db('website').$postCat.'/'.$postArt.'/">';


// EQ add show_message
$_SESSION['comment_message'] = array(
'reason' => $commentReason,
'status' => $commentStatus,
'back_link' => $back_link
);

show_message( $_SESSION['comment_message'] );
header("Location: http://path/to/comment-message.html");
}


// End Snipped of the comments function


function show_message( $array ) {
if(isset($_GET['notification'])) {
echo '<h2>' .$array['status'] .'</h2>';
echo !empty($array['reason'])
? '<p>' .$array['reason'] .'</p>'
: '';
echo '<p><a href="'. db('website') .'">Back Home</a> || <a href="' . $array['back_link'] . '">Back to Article</a></p>';
die();
}
}

Then the static HTML file, I have called comments-message.html as noted in the above header line above
Code: [Select]
<!doctype>
<html>
<head>
</head>
<body>
<div id="messageDiv"></div>
<script>
window.onload = get_message;

function get_message() {
request(
'snews.php?notification=TRUE',
null,
function() {
var div = document.getElementById('messageDiv');
div.innerHTML = this.responseText;
},
'GET'
);
return false;
}

function XHR() {
var xhr = false;
xhr = window.ActiveXObject
? new ActiveXObject("Microsoft.XMLHTTP")
: new XMLHttpRequest();
return xhr;
}
function request( url, snd, callback, type ) {
var http = XHR();
if (http) {
http.onreadystatechange = callback;
};
http.open(type, url, true);
if (type == "POST") {
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", snd.length);
http.setRequestHeader("Connection", "close");
}
http.send(snd);
}
</script>
</body>
<html>


My test that gave me the guess for the above looks like this:
Code: (test.php) [Select]
<?php

error_reporting
(E_ALL E_NOTICE);

session_start();

function 
comment() {

if( isset($_GET['state']) || isset($_SESSION['state']) ) {
$state '';

if($_GET['state'] == 'ok' || $_SESSION['state'] == 'ok') {
if( isset($_GET['appr']) || isset($_SESSION['appr']) ) {
$state 'waiting';
$status 'comment_sent_approve';
} else {
$state 'sent';
$status 'comment_sent';
}
$reason '';
} else {
$state 'error';
$status 'comment_error';
$reason 'some reasons';
}
$back_link 'test.php';

$_SESSION $_GET;

$_SESSION['comment_message'] = array(
'state' => $state,
'reason' => $reason,
'status' => $status,
'back_link' => $back_link
);

show_message$_SESSION['comment_message'] );
header("Location: http://localhost/www/projects/comment-message.html");
} else {
echo '<a href="test.php?state=ok">Comment Ok</a> || <a href="test.php?state=ok&appr=yes">Comment Waiting</a> || <a href="test.php?state=error">Comment Error</a>';
}
}

function 
show_message$array ) {
if(isset($_GET['notification'])) {
echo '<h2>' .$array['status'] .'</h2><h4>Current State - ' .$array['state'] .'</h4>';
echo !empty($array['reason'])
'<p>' .$array['reason'] .'</p>'
'';
echo '<p><a href="test.php">Back Home</a> || <a href="' $array['back_link'] . '">Back to Article</a></p>';

echo 'Session: <br /><pre>';
print_r($_SESSION);
echo '</pre><br />';
echo 'GET: <br /><pre>';
print_r($_GET); 
echo '</pre>';

die();
}
}

comment();

?>


The static HTML is the exact same comments-message.html as above but the file call is different
« Last Edit: March 18, 2011, 10:28:24 PM by nukpana »
Logged

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
« Last Edit: April 15, 2012, 03:48:49 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”
Pages: 1 [2]