html in form

Discussion in 'Programming' started by SiteExpress, Jul 30, 2006.

  1. #1
    I have a text area for users to input text. That text is the inserted into a database and displayed on a page. How can I allow users to insert basic html into the submit form?

    Just wanting basic html like p, br, href
     
    SiteExpress, Jul 30, 2006 IP
  2. MakZF

    MakZF Well-Known Member

    Messages:
    390
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    140
    #2
    You could make different codes for people to use like [p] and [link=site.com]Click here[/url]. You could use the script to turn the tags into real html after using htmlspecialchars() to filer out any other unwanted HTML.
    For <br /> tags it'd be easier to use nl2br().
     
    MakZF, Jul 30, 2006 IP
  3. SiteExpress

    SiteExpress Well-Known Member

    Messages:
    1,355
    Likes Received:
    153
    Best Answers:
    0
    Trophy Points:
    155
    #3
    Actually, I am the only one that will be using this form. Well, myself and my partner.

    SO, I am not worried about what characters and such. Current, if I put in a <p></p>, that is exactly what is displayed on the generated page. How can I make it generate html out of the characters?
     
    SiteExpress, Jul 30, 2006 IP
  4. danielbruzual

    danielbruzual Active Member

    Messages:
    906
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    70
    #4
    try to use htmlentities($string) when inserting into the database.
     
    danielbruzual, Jul 30, 2006 IP
    ramakrishna p and SiteExpress like this.
  5. SiteExpress

    SiteExpress Well-Known Member

    Messages:
    1,355
    Likes Received:
    153
    Best Answers:
    0
    Trophy Points:
    155
    #5
    Got it. Worked like a charm... Thanks for the help.
     
    SiteExpress, Jul 30, 2006 IP
  6. danielbruzual

    danielbruzual Active Member

    Messages:
    906
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    70
    #6
    No problem. I came across the same problem yesterday since I'm coding and admin backend for one of my sites where I can add messages to a database.
     
    danielbruzual, Jul 30, 2006 IP
  7. talentcoder

    talentcoder Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    use regular expression to filter out all HTML tags except p, br, href
     
    talentcoder, Aug 3, 2006 IP