Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: getting quotes

  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts

    getting quotes

    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

    Quote Originally Posted by Mullett
    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

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Create a hidden form (method="post") with a hidden input named something like "quote_text."

    html:
    Code:
    <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:
    Code:
    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.
    Last edited by itsallkizza; 10-17-2008 at 11:29 PM.

  • #3
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    ok so far i have this

    Code:
    <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

  • #4
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    also how is the exactly grabbing my text??

  • #5
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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:
    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>
    *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).
    Last edited by itsallkizza; 10-19-2008 at 11:59 PM.

  • #6
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    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

  • #7
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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:
    Code:
    <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.

  • #8
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    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 ??

  • #9
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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][ /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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •