AJAX - check if topic allready exist (request)

This forum is now closed as part of retiring phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
spamyboy
Registered User
Posts: 93
Joined: Sun Feb 04, 2007 8:15 am

AJAX - check if topic allready exist (request)

Post by spamyboy »

AJAX - check if topic allready exist (request)
Simply when you post for e.g. "Flash games" and topic allready exist, script should print abow topic name field "Topic with that title exist allready $link"
$link - Link to that topic ( <a href="topic addres">topic name</a> ).
p.s. If topic allready exist with that title, script shouldnt allow post it.
p.p.s. If there is more then one allready posted, it should display newest by ID.
User avatar
iyeru42
Registered User
Posts: 1120
Joined: Wed Feb 01, 2006 7:22 pm
Location: Madison, WI
Contact:

Post by iyeru42 »

That kind of AJAX would have to be done with PHP (due to getting MySQL). However, that's impossible due to what AJAX stands for: Asynchronous Javascript And XML.

Key word: JavaScript
My Website | My MOD Requests | Foreign Key Docs (some topics are not requests)
"It's easy to rebel, but it's hard to be recognized."
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Post by Brf »

LOL. Of course you can use Ajax with phpBB.
User avatar
iyeru42
Registered User
Posts: 1120
Joined: Wed Feb 01, 2006 7:22 pm
Location: Madison, WI
Contact:

Post by iyeru42 »

Yeah, but what he's saying is if you could do the following:

Code: Select all

// Post Function (Topic) Here
// ...

$result = mysql_query("SELECT * FROM `phpbb_topics`");
$topics = mysql_fetch_array($result);

// Initiate PHP <> JS Connector
// ...

?><script> topic_res = new Array();
topic_res[] = </script><?php $topics ?> ;

// Do AJAX here.
My Website | My MOD Requests | Foreign Key Docs (some topics are not requests)
"It's easy to rebel, but it's hard to be recognized."
spamyboy
Registered User
Posts: 93
Joined: Sun Feb 04, 2007 8:15 am

Post by spamyboy »

iyeru42, your comment was totaly stupid.. I mentionet AJAX in topic title only couse rarely who is scripting AJAX in thease days (couse it's kinde of new "language"). You do need php to get info from sql & I do understan that, the only problem is that I event couldnt call my self begginer in ajax (JS).

So could pleas anyone write this mod ?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Post by Brf »

I agree. It appears that iyeru42 does not know what he is talking about...

To use Ajax to do something like that, you simply create a new phpBB webpage which looks up that Topic and returns the info about the existing Topic.

The checker would use Ajax to call up the new webpage, and check the result. If positive, it could make a popup with the existing topic info, or fill in a message space on the posting webpage.
spamyboy
Registered User
Posts: 93
Joined: Sun Feb 04, 2007 8:15 am

Post by spamyboy »

bump :|
spamyboy
Registered User
Posts: 93
Joined: Sun Feb 04, 2007 8:15 am

Post by spamyboy »

anyone ?
spamyboy
Registered User
Posts: 93
Joined: Sun Feb 04, 2007 8:15 am

Post by spamyboy »

Bump...
thetruecoolness
Registered User
Posts: 94
Joined: Sat Feb 17, 2007 6:32 am
Location: GA
Contact:

Post by thetruecoolness »

Well the best way is to do something like this.

topic_check_response.php

Code: Select all

/*Standard php hack prevent for user facing file*/
define('IN_PHPBB', true);
$phpbb_root_path = './../';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);

/* Use an SQL query to check if HTTP_POST_VARS['topic_name'] exists in the TOPICS_TABLE, if so echo <a href="topic address">topic_name</a> */
Then create your JS in the posting_body.tpl.

Code: Select all

<script type="text/javascript">
<!--//--><![CDATA[//><!--
/*
Deals with XMLHttpRequest object
from www.w3schools.com
*/
function GetXmlHttpObject()
{
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	} // if (window.XMLHttpRequest)
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	} // else if (window.ActiveXObject)
	return objXMLHttp;
} // function GetXmlHttpObject()

function check_topic(topic_name)
{
	topicCheckRequest = GetXmlHttpObject();
	if (topicCheckRequest ==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	topicCheckRequest.onreadystatechange = topic_check_response;
	topicCheckRequest.open("POST", {U_TOPIC_CHECK}, true);
	topicCheckRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	readRequest.send('topic_name=' + topic_name);
}

function topic_check_response()
{
	if (topicCheckRequest.readyState==4 || topicCheckRequest.readyState=="complete")
	{
		if (readRequest.responseText == null || readRequest.responseText.replace(/\s/g, '').length <= 1)
		{
			document.getElementById('topic_warning').innerHTML = "Topic name already exists " + topicCheckRequest.responseText;
		}
	}
}
//--><!]]>
</script>
Then replace

Code: Select all

	  <td class="row2" width="78%"> <span class="gen"> 
		<input type="text" name="subject" size="45" maxlength="60" style="width:450px" tabindex="2" class="post" value="{SUBJECT}" />
		</span> </td>
with

Code: Select all

	  <td class="row2" width="78%"> <span class="gen"> 
		<input type="text" name="subject" size="45" maxlength="60" style="width:450px" tabindex="2" class="post" value="{SUBJECT}" onkeyup="check_topic(this.value);" />
		</span>
		<div id="topic warning"></div>
	  </td>
and add the following template variable to posting.php

Code: Select all

'U_TOPIC_CHECK' => append_sid('topic_check_response.php')
And this is how AJAX works, Javascript sends an XMLHTTPRequest to a PHP page you write, which then sends a response back to the Javascript.
spamyboy
Registered User
Posts: 93
Joined: Sun Feb 04, 2007 8:15 am

Re: AJAX - check if topic allready exist (request)

Post by spamyboy »

Thanks !
mgutt
Registered User
Posts: 346
Joined: Tue Sep 21, 2004 2:54 pm
Location: Germany, Sankt Augustin
Contact:

Re: AJAX - check if topic allready exist (request)

Post by mgutt »

Hi,

I like this idea. But I can't see a timeout or something like that.

Because every time the user presses a new key a new request is made, right?

Won't it be better to do the request if the post_message field is onfocus()?

regards
Marc
Forums: Honda || phpBB Categories Hierarchy
Mods: Spamfilter against bot registrations || Seo Urls
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: AJAX - check if topic allready exist (request)

Post by Brf »

mgutt wrote: Won't it be better to do the request if the post_message field is onfocus()?
The onkeyup which calls the ajax function is on the Subject input field. Therefore the request is made only when the Subject is being changed.
mgutt
Registered User
Posts: 346
Joined: Tue Sep 21, 2004 2:54 pm
Location: Germany, Sankt Augustin
Contact:

Re: AJAX - check if topic allready exist (request)

Post by mgutt »

No it is called every time you release the key. So if you write "phpBB" it calls the function 5 times ;)
Forums: Honda || phpBB Categories Hierarchy
Mods: Spamfilter against bot registrations || Seo Urls
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: AJAX - check if topic allready exist (request)

Post by Brf »

mgutt wrote:No it is called every time you release the key.;)
No. Every time you release a key when the focus is on this input field:

Code: Select all

<input type="text" name="subject" size="45" maxlength="60" style="width:450px" tabindex="2" class="post" value="{SUBJECT}" onkeyup="check_topic(this.value);" />
Which is the subject. If you type phpBB into the Subject field, it would call it five times,
It makes more sense to use the "onblur" which is only called when the subject loses focus.
Post Reply

Return to “[2.0.x] MOD Requests”