...

View Full Version : getting quotes



runnerjp
10-17-2008, 09:08 PM
ok every forum has this function hwere you click a link/button that says "Insert Quote" and the quote is inserted into the text box...

so if im on the forum thread how can i do it so the link takes me to my replypage and insert the quote into a textbox....

so im on my threadpage which is just forum.php and there is a link saying quote... once clicked it sends me to my reply page reply.php and inserts the quote example



this is my quote


im persuming the quotelink would be something like thread=id of thread&quote=id of quote


searched that net with no look for this one

itsallkizza
10-17-2008, 10:24 PM
Create a hidden form (method="post") with a hidden input named something like "quote_text."

html:


<form id="hiddenQuoteSendOff" action="reply_handler.php" method="post" style="display:none;">
<input type="hidden" name="quote_text" value="" />
</form>


Use something like this to grab the text the user has selected onclick:


function quoteThis()
{
var txt = '';
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
else txt = "";
var hiddenForm = getElementById("hiddenQuoteSendoff");
hiddenForm.quote_text = txt;
hiddenForm.submit();
}


Then on your reply handler php script you need to add a check to see if the $_POST("quote_text") variable exists, if it does, insert your quote formatting along with the text into the reply textarea.

runnerjp
10-19-2008, 04:46 PM
ok so far i have this


<form id="hiddenQuoteSendOff" action="index.php?page=reply&id=230" method="post" style="display:none;">
<input type="hidden" name="quote_text" value="" />
</form>
<a href="#" onclick="return quoteThis(<?php print "'".$postid."'"; ?>,<?php print "'".$userid."'"; ?>);">quoteit</a>
<script> function quoteThis(postnr, postuser)
{
var txt = '
' +'Post #' + postnr + ' by' + postuser;
if (window.getSelection)
{
txt += window.getSelection() + '';
}
else if (document.getSelection)
{
txt += document.getSelection() + '[/quote]';
}
else if (document.selection)
{
txt += document.selection.createRange().text+ '[/quote]';
}
else txt = "";
var hiddenForm = document.getElementById("hiddenQuoteSendOff");
hiddenForm.quote_text.value = txt;
hiddenForm.submit();
return false;
}</script>
but im not sure how i would get it to past in the textbox on the reply.php page??

the textbox is named replys if that helps

runnerjp
10-19-2008, 05:49 PM
also how is the exactly grabbing my text??

itsallkizza
10-19-2008, 10:57 PM
I'm a little confused at your code after "var txt = '"... Is the a bbcode conflict? Cuz it's looking funny...

Anyway, the javascript function is grabbing the text that is currently selected (as in highlighted by dragging your mouse over it). It is then posting all that text to your index.php?page=reply page.

Your next step is to open up your index.php?page=reply page (whether or not that is a redirect I don't know without seeing your code). Then you need to add some php script to grab the $_POST("quote_text") variable and insert it into your textarea.

It would be easier for me to help if I could also see your reply handler's php code, but between then and now I'd suggest something as simple as this:


<textarea>
<!-- this is where your reply text is going to be typed -->
<?php
if (array_key_exists($_POST["quote_text"])){
echo ("[quote]" . $_POST["quote_text"] . "[ /quote]");
}
?>
</textarea>


*remove the space from: [ /quote]

Note: Don't add the bbcode before your post the data (I think that's what you were trying to do in your javascript).

runnerjp
10-19-2008, 11:50 PM
ok i found the problem i dont watn to highlight it... i just want it to be copied so depends on what reply i want to quote it copys that quote!!..

$message sends the quote


like on here where u click quote and it does it auto maticly and u dont have to hilight anything

itsallkizza
10-20-2008, 03:07 AM
Oh ok, well that's actually a lot easier to do (not as cool though lol ;)).

Well there are a lot of ways you can go about it then.

You can fairly easily just echo the database primary key of the each post into each quote button, something like this:


<form class="quote_post" action="index.php?page=reply" method="post">
<input type="hidden" name="pkey" value="<?php echo($postkey) ?>" />
<input type="image" value="Quote" src="images/quote_post.jpg" />
</form>


On each thread load you would need to insert the pkey id into each post.

If you already have a form submit somewhere that you need to run instead of that one, then you can just make it a div/button with an onclick that runs a javascript function with that same echoed key in there.

You can then grab the post data on the reply handler straight from your database.

There are dozens of other methods, but that's what I would do, it's the most modular method I can think of without seeing all your code and the way its structured.

runnerjp
10-20-2008, 11:38 AM
so basicly store the message and then post it on the next page lol... sounds easy to me

how would i add the [code ] [/ code] tags ??

itsallkizza
10-20-2008, 10:07 PM
Ya you got it ;) I tried to explain it in detail in case you weren't as web savvy as you apparently are lol, and of course for others with similar questions.

Add the
[ /code] tags at the same time you insert the quote text. I'm re-quoting from above:

[code]
<textarea>
<!-- this is where your reply text is going to be typed -->
<?php
if (array_key_exists($_POST["quote_text"])){
echo ("[ quote]" . $_POST["quote_text"] . "[ /quote]");
}
?>
</textarea>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum