5 Replies - 5557 Views - Last Post: 10 November 2010 - 02:49 PM

#1 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Displaying HTML in a textarea?

Posted 09 November 2010 - 09:18 AM

I'm building a Rails blog-like site and I'm having trouble with a text area. That said, I'm assuming this is an HTML problem and not a Rails problem....but I won't be surprised if this gets kicked over to Ruby...

Whenever I create a new post that has information inputted via <textarea>, it will not display html links that I put into it.

For example...
I create a new post which submits information via <textarea>. The post shows up on the screen in plain text instead of showing the <a> links that I posted in the <textarea>. This is a snippet of the post:

Quote

Ruby on Rails

Test page for a "Ruby on Rails" knode... <u><h3>Links</h3></u> <br> <a href="http://mislav.uniqpath.com/poignant-guide/book/">Why's (poignant) Guide to Ruby</a>

Cat: Programming

Tag: ruby, rails,


The source shows:

<p>
   <h1>Ruby on Rails</h1>
</p>

<p>
  Test page for a &quot;Ruby on Rails&quot; knode...

&lt;u&gt;&lt;h3&gt;Links&lt;/h3&gt;&lt;/u&gt;

&lt;br&gt;
&lt;a href=&quot;http://mislav.uniqpath.com/poignant-guide/book/&quot;&gt;Why's (poignant) Guide to Ruby&lt;/a&gt;

</p>

<p>
  <b>Cat:</b>
  Programming
</p>

<p>
  <b>Tag:</b>
  ruby, rails, 
</p>


Should I be using a different input than <textarea> to input my data as inserting HTML is not possible? Or am I missing something in how I'm making the post?

Is This A Good Question/Topic? 0
  • +

Replies To: Displaying HTML in a textarea?

#2 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 6216
  • View blog
  • Posts: 10,731
  • Joined: 28-September 07

Re: Displaying HTML in a textarea?

Posted 09 November 2010 - 09:32 AM

A textarea is just that. An area for simple text. You can use CSS to style the text, but HTML will not work within the textarea tags.
Was This Post Helpful? 1
  • +
  • -

#3 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Re: Displaying HTML in a textarea?

Posted 09 November 2010 - 10:17 AM

View PostBenignDesign, on 09 November 2010 - 07:32 AM, said:

A textarea is just that. An area for simple text. You can use CSS to style the text, but HTML will not work within the textarea tags.

Damn, that's what I figured. Shot in the dark here... any suggestions on how to input text and show it on a page and does display html properly?
Was This Post Helpful? 0
  • +
  • -

#4 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 6216
  • View blog
  • Posts: 10,731
  • Joined: 28-September 07

Re: Displaying HTML in a textarea?

Posted 09 November 2010 - 11:48 AM

You could have two form fields: one to hold the url and one to hold the text to be linked.

When you pull the data back out of your data source, add these pieces of data to the code.

If that makes any sense whatsoever.

To illustrate my point... I'm a PHP coder. I generally use a MySQL database for a data source.
A user entering data into my form gives values for variables called $url and $linktext. When I display this information on its web destination, I connect to the database and run a query for the information. I then piece together the link like so:

<a href="<?php echo $url; ?>"><?php echo $linktext; ?></a>


Was This Post Helpful? 0
  • +
  • -

#5 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Re: Displaying HTML in a textarea?

Posted 09 November 2010 - 12:17 PM

Thanks a lot for the input. 2 answers to what you said... mostly listed here for posterity, as I think i've found another solution to my problem...

a) i get what you're doing with the php. I'm using a mySQL db as well. To have it listed using 2 sources the ruby code would be:

<%= link_to @posts_info, posts_path %>



where @posts_info is what was originally assigned to the post made and posts_path is the link given....

Regardless, this won't work for a looooooooooooooong post because link_to would be a burden to throw on the whole textarea... so...

B) I'm fixing all of this by installing a rails version of tinyMCE...so i'm just going to cheat to get the effect I want. :)

Thanks!
Was This Post Helpful? 0
  • +
  • -

#6 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Re: Displaying HTML in a textarea?

Posted 10 November 2010 - 02:49 PM

Ok...so I think I asked the question wrong earlier...

After I submit the information in the textarea to be submitted to the new post, it's only displaying the plain text version of the html.

How do I get the post to show the actualy HTML and not plain text?

View the source I posted in the original post to see what it's doing.

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1