Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Comment posting questions  (Read 421 times)

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Comment posting questions
« on: October 26, 2012, 09:05:05 AM »

In the process of doing some changes to the comment submission form.  I added an email label and made both name and email required.  Patch #15 - 1.7.0 made name set to anonymous if it was blank... I changed that along with the preg_match.

Anyways, what I am looking to do is when a user submits a comment and a field fails an 'invalid' or other warning is shown next to the field.

First problem is the default goes to a 'blank' page and shows the default errors.  Would this be as simple as changing the following :

Code: [Select]
if ($fail){
$back_link = _SITE.$postCat.$postArt;
echo '<a href="'.$back_link.'/">'.l('back').'</a>';
} else {
echo '<meta http-equiv="refresh" content="1; url='._SITE.$postCat.$postArt.'/">';
}

to

Code: [Select]
echo '<meta http-equiv="refresh" content="1; url='._SITE.$postCat.$postArt.'/">';
?

My plan is to store an error variable for the required fields then output the 'invalid' or whatever in the comment form if set or nothing if null.  These variables would also need to be stored in the session as well similar to $_SESSION[_SITE.'comment']['name'] = $name; - correct?  I'm assuming with them stored in the session they could be read and output the proper changes whether just a notification or chaning the color of the entry field.

Also, is it possible to refresh to a #tag similar to how comments can be linked to?  This way I could add a tag to the form and it will refresh to it rather than the user needing to scroll down.

thanks guys... been playing with this for about a week and this is addicting!  I cannot count the number of changes I have made, most found on this site with minor changes, and some of my own.  End goal is to have a custom 'template' of snews which I can install where needed and make minor css changes to fit into whatever site need be.
« Last Edit: October 26, 2012, 09:07:24 AM by mihomes »
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Comment posting questions
« Reply #1 on: October 26, 2012, 12:55:57 PM »

Quote
Anyways, what I am looking to do is when a user submits a comment and a field fails an 'invalid' or other warning is shown next to the field.
I would use Javascript/AJAX for this.

Quote
Also, is it possible to refresh to a #tag similar to how comments can be linked to?  This way I could add a tag to the form and it will refresh to it rather than the user needing to scroll down.
Yes, you can use the id as the hash on the refresh. Ideally, you put the comment form above the comments...
« Last Edit: October 26, 2012, 01:18:57 PM by nukpana »
Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: Comment posting questions
« Reply #2 on: October 26, 2012, 08:32:15 PM »

Okay, I got everything working minus one thing...

I changed the meta refresh to

Code: [Select]
echo '<meta http-equiv="refresh" content="0; url='._SITE.$postCat.$postArt.'/#PostComment">';
Content 0 means there is no pause before refresh and #PostComment is an id I entered right above the submission form so it goes back to that area of the page.

Problem is after submission there is a blank page (regular template just without anything in the content) that shows very breifly then it 'refreshes' with the correct content.  I was able to submit and pause the screen very quick... this is the content area shown in that blank page :

Code: [Select]
<div id="main">
<meta http-equiv="refresh" content="0; url=http://www.example/blog/announcements/testing/#PostComment"> </div>

I'm assuming the time it shows is just the time it takes to reach that part of snews.php?
Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: Comment posting questions
« Reply #3 on: October 26, 2012, 11:19:19 PM »

Ran into another problem... if the comment is submitted on a paginated page then

Code: [Select]
echo '<meta http-equiv="refresh" content="0; url='._SITE.$postCat.$postArt.'/#PostComment">';
doesn't refresh if I am posting from a paginated page... it refreshes to the default snews directory.  Going to need some help with this one.
Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: Comment posting questions
« Reply #4 on: October 28, 2012, 06:15:41 AM »

Still can't figure this one out as I don't understand the structure of how the categories are setup :

In the comments function :

Code: [Select]
$postArt = clean(cleanXSS($_POST['article']));
$postArtID = retrieve('category','articles','id',$post_article_id);
if ($postArtID == 0) {
$postCat = '' ;
} else {
$postCat = cat_rel($postArtID, 'seftitle').'/';
}
// if ($fail){
// $back_link = _SITE.$postCat.$postArt;
// echo '<a href="'.$back_link.'/">'.l('back').'</a>';
// } else {
echo '<meta http-equiv="refresh" content="0; url='._SITE.$postCat.$postArt.'#PostComment">';
// }

Basically all this does is refresh to the page the user submitted a comment from.  I am having some problems with defining the correct link though...all I need is to be able to enter the same url I am.

For example, with 'blog' being my snews directory, submitting a comment from /blog/other/test/ refreshes correctly to /blog/other/test/#PostComment

Submitting from /blog/other/test/c_2/ (second page of comments) will refresh to /blog/other/c_2/#PostComment (removes the article name)

Lastly, if submitting from a subcat like /blog/other/testing/test/c_2/ it refreshes to the main article page /blog/other/testing/test/#PostComment which actually is fine although it would be nicer to refresh to the page they were on.

Can anyone help me out with this one?
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Comment posting questions
« Reply #5 on: October 28, 2012, 02:57:42 PM »

Well, there should be a commentsPage global if I recall.  You can use that :
(not real code)
$cPage = '';
if( $commentsPage )
    $cPage = $commentsPage;

$link =_SITE.$postCat.$postArt.$cPage

Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: Comment posting questions
« Reply #6 on: October 28, 2012, 06:22:55 PM »

I've been echo'ing variables to see their values and they are all over the place... I think you were referring to $commentsPage which I am outputting as well...

I don't understand why the 'tree' for snews is setup so strangely... it should as simple as working with cat, subcat, article, cpage... I ran into the same problem when I modified the page titles with name, xname, title - they bounce all over the place and are never consistent.
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Comment posting questions
« Reply #7 on: October 28, 2012, 08:11:33 PM »

If all else fails, you still can call the global $url and call it like so: _SITE . $url . '/#'. $commentID
Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: Comment posting questions
« Reply #8 on: October 28, 2012, 10:36:20 PM »

If all else fails, you still can call the global $url and call it like so: _SITE . $url . '/#'. $commentID

That has no use as it will only return the sites install directory because index.php is the only file... essentially what I need is a $_SERVER["REQUEST_URI"]; but the format in which snews is setup...
Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: Comment posting questions
« Reply #9 on: October 28, 2012, 11:20:30 PM »

The following seems to work in getting the right article location except when doing so from a comment page :

Code: [Select]
$postArt = clean(cleanXSS($_POST['article']));
$postArtID = retrieve('category','articles','id',$post_article_id);
$postCat = cat_rel($postArtID, 'seftitle').'/';
$sub_refresh = $postCat.$postArt.'/';

From /snews/main-cat/article/ returns to /snews/main-cat/article/ although

from /snews/main-cat/article/c_2/ returns to /snews/main-cat/c_2/

So same as above... need to be able to return the correct location when from a comment page and two, need to be able to know what comment page I am on so I can return that as well.

This is driving me nuts - it should not be soo hard, but then again I don't understand how the heck these locations are saved what-so-ever!
« Last Edit: October 28, 2012, 11:22:32 PM by mihomes »
Logged

mihomes

  • Newbie
  • *
  • Karma: 2
  • Posts: 23
Re: Comment posting questions
« Reply #10 on: October 29, 2012, 12:22:42 AM »

Okay, with the help of some functions and one I did not know about I have a solution that works :

Code: [Select]
$postCatID = retrieve('category','articles','id',$post_article_id);
$postCategory = cat_rel($postCatID, 'seftitle').'/';
$postArticle = retrieve('seftitle','articles','id',$post_article_id);

echo '<meta http-equiv="refresh" content="0; url='.$postCategory.$postArticle.'/#PostComment">';

With that said, is there any way to tell what comment page I am on, if on one?
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Comment posting questions
« Reply #11 on: October 29, 2012, 09:50:04 AM »

If all else fails, you still can call the global $url and call it like so: _SITE . $url . '/#'. $commentID

That has no use as it will only return the sites install directory because index.php is the only file... essentially what I need is a $_SERVER["REQUEST_URI"]; but the format in which snews is setup...
Sorry, I was doing these suggestions from memory and I forgot, the form calls index.php - unlike this mod here that uses the current url as the form action -> http://snewscms.com/forum/index.php/topic,10096.0.html

Okay, with the help of some functions and one I did not know about I have a solution that works :

Code: [Select]
$postCatID = retrieve('category','articles','id',$post_article_id);
$postCategory = cat_rel($postCatID, 'seftitle').'/';
$postArticle = retrieve('seftitle','articles','id',$post_article_id);

echo '<meta http-equiv="refresh" content="0; url='.$postCategory.$postArticle.'/#PostComment">';

With that said, is there any way to tell what comment page I am on, if on one?
You may have to pass the comment page as a hidden field as with the article id.
Logged