Textfield

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Miha
Forum Newbie
Posts: 10
Joined: Mon Aug 21, 2006 12:44 pm

Textfield

Post by Miha »

Hi!

I have an input textfield and i would like to make a couple of buttons, one to add bold tag around text highlighted in a text field, another to add URL tag around highlighted text. For example like on this forum, when you are posting a new topic or reply. How is this done??

regards Miha.
User avatar
bmcewan
Forum Commoner
Posts: 55
Joined: Wed Jun 02, 2004 7:19 am
Location: West Yorkshire, UK.

Post by bmcewan »

It is called BBCode, might be worth checking http://www.google.co.uk/search?hl=en&q= ... gle+Search or indeed this article i found in the search http://www.sitepoint.com/article/bb-cod ... pplication.

You should have some pointers here, if you get stuck, post some code and we'll try to help you out and point you in the right direction.
Miha
Forum Newbie
Posts: 10
Joined: Mon Aug 21, 2006 12:44 pm

Post by Miha »

bmcewan: not quite what i was looking for, but thanks anyway!

I guess i wasn't clear enough....i'm just looking for the functionality, if you highlight a part of a string in a input textfield and you click on a button, it will add some predefined substring before and after highlighted text....

So: I drag a mouse over some text, click on a button, and it will automaticly add '<b>' before, and '</b>' after that highlighted part of text...

I guess i would have to write a function, that will get the string from that textfield, find out the position where the highlighted part of a string in that textfield starts and where is stops. Than redefine that string -> add </b> at stop position, and add <b> at start position. Than return redefined text to that textfield...That's my teoretical pseudo-code-idea....i have no experience in php, so I have no idea if this is posible and no idea how to implement this thing in php.... I hope you guys can advise me how to implement this idea and what functions might be useful to me.

regards, Miha.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You seem to be describing a WYSIWYG input such as TinyMCE, unless you visually want to see the tag code. In that case, look at the post building code used by the forum. It's all in the pages.
Miha
Forum Newbie
Posts: 10
Joined: Mon Aug 21, 2006 12:44 pm

Post by Miha »

Actually i don't need WYSIWYG. I don't mind to see this tags... I checked TinyMCE, it's almost what I'm looking for, it's just a bit too complex. I only need to simplify inputting text for an "almost-computer-illiterate secretary" when she is posting news on a site. Now she has to put(write) <b> and </b> tags manualy, OK sometimes she manages to write this right, but i don't want to mention, when she needs to write <a href="www.something.si">www.something.si</a> ...that's the real problem.:) There are allways some typos here. Anyway...she is only allowed to add these two tags, because of page graphical design restrictions. Tiniest TinyMCE still has at least 5 options. What's better: customize TinyMCE, or develop this from scratch? Will i end up drinking if i try any of these? :)

BTW: feyd: I can't find that post that you were talking about. Maybe that post can answer all my question.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The post building page I'm referring to is the one you type your messages in to post.

posting.php?mode=reply&t=54863 for this thread's for instance.
Miha
Forum Newbie
Posts: 10
Joined: Mon Aug 21, 2006 12:44 pm

Post by Miha »

Oh OK i got it, a little misunderstanding. :oops: :roll:
Post Reply