Jump to content

creating a quote button


Anarchatos

Recommended Posts

Hey, I'm trying to make my own quote button. It kinda works, except when I'm trying to quote posts that have more than 1 line.

Basically the idea is that, next to every post there is a Quote button. When you click on it, the entire post gets copied all the way down to the textarea for creating a new post.

 

<input type="button" value="Quote" onclick="this.form.post.value+='[quote]{$post}[/quote]';">

 

I'm currently using the above code (doesn't get much simpler than that), but I've also tried using javascripts. It all came down to the same.

 

Anyone know how to do this? :-\

Link to comment
https://forums.phpfreaks.com/topic/101442-creating-a-quote-button/
Share on other sites

<FORM NAME='form1' ID='form1'>
<TEXTAREA NAME='post'>Here is some text.</TEXTAREA>
<input type="button" value="Quote" onclick="document.form2.post2.value='[quote]'+document.form1.post.value+'[/quote]';">
</FORM>
<BR>
<FORM NAME='form2' ID='form2'>
<TEXTAREA NAME='post2'></TEXTAREA>
</FORM>

There isn't much code involved with the quoting, basically the page consists of:

 

// Show all posts on the page
$query = mysql_query("SELECT * FROM im_forum_posts WHERE topic_id = '$thistopic' ORDER BY initialpost DESC, posted_on ASC LIMIT $from, $max");
while ($row = mysql_fetch_array($query)) {
$post_id = $row['post_id'];
// etc
// print the posts in the while loop
// use the following button as the Quote button:
<input type="button" value="Quote" onclick="this.form.post.value+='$qtext';">
}

// create a form for new posts
<form name='newpost' action='showtopic.php?topic=$topic_id' method='post'>
Post: <br><textarea name='post' id='post' rows='10' cols='45' style='border:1px solid #a0bee7; background-color: #f1f7ff;'></textarea>
<input type='submit' name='postreply' value='Post' style='border:1px solid #a0bee7; background-color:#f1f7ff;'>
</form>

 

I've also tried functions such as

function addtext() {
var newtext = document.newpost.quote.value;
document.newpost.post.value += newtext;
}

but they don't work either

 

maybe a live example will help?

I'm currently testing the forum script on the following site:

 

http://h1380095.stratoserver.net/forums/showtopic.php?topic=6 (don't look at broken links/images, it's a test site)

 

When I try to Quote the last post (which is in fact one incredibly long line without breaks), it works. When I try to Quote 3rd, 5th or 6th post (counting from top), it works. Just not with posts that have 'breaks'.

 

Example:

"bla bla bla" would be quoted

but

"bla

bla

bla" would not be quoted

if i'm reading your code correctly, this is not inside a form, so this.form doesn't exist:

 

<input type="button" value="Quote" onclick="this.form.post.value+='$qtext';">

 

you should watch for Javascript errors. this would probably throw one.

 

another thing: It may be a bad idea to name any field 'post', though i'm not sure about that. if you say document.form1.post, the post method is probably implied

My bad,

<form name='newpost' action='showtopic.php?topic=$topic_id' method='post'>

is actually above the while loop. It should look like this:

 

<form name='newpost' action='showtopic.php?topic=$topic_id' method='post'>
// while loop
<input type="button" value="Quote" onclick="this.form.post.value+='$qtext';">
// end while loop
Post: <br><textarea name='post' id='post' rows='10' cols='45' style='border:1px solid #a0bee7; background-color: #f1f7ff;'></textarea>
<input type='submit' name='postreply' value='Post' style='border:1px solid #a0bee7; background-color:#f1f7ff;'>
</form>

 

I also tried renaming the textarea, but it gives exactly the same results.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.