How to pur {$desc} in a form(text area)?

Discussion in 'Programming' started by nevret2, Jun 8, 2008.

  1. #1
    hello, i have {$desc} in my website file, example it gives a discriotion like:

    Monday Night Conversation is our candid conversation with stars of the big and small screen, athletes, entertainers, politicians and other icons.
    
    In this episode, BlackTree TV Executive Producer, Ja...
    Code (markup):
    but this is too long, so i want the discrioption in a form (text area)


    so i want put {$desc} into:

    <form name="form1" method="post" action="">
      <label>
      <textarea name="textarea" cols="30" rows="10"></textarea>
      </label>
    </form>
    Code (markup):

    how can i do this?

    i did it like:
    
    <textarea name="textarea" cols="30" rows="2">{$desc}
    </textarea>
    Code (markup):
    but then as discription it givies:

    Monday Night Conversation is our candid conversation with stars of the big and small screen, athletes, entertainers, politicians and other icons.<br></br><br></br>In this episode, BlackTree TV Executive Producer, Ja... 
    Code (markup):
    what are those <br></br><br></br>?

    can someone please fix this

    thnx
     
    nevret2, Jun 8, 2008 IP
  2. AFitch

    AFitch Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You echo a PHP variable like this:
    
    <?
    echo $desc;
    ?>
    
    PHP:
    <br> is a line break. It brings you to the next line.
     
    AFitch, Jun 8, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    
    $desc = str_replace('<br/>',"\n",$desc);
    
    PHP:
    Place that code somewhere in the code (it looks like you are using template).

    <br/> is a newline character, which is the same as \n in textarea.

    Peace,
     
    Barti1987, Jun 8, 2008 IP
  4. nevret2

    nevret2 Peon

    Messages:
    518
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hello,

    i made it like:
    
    <form name="form1" method="post" action="">
      <label>
      <textarea name="textarea" cols="30" rows="10">$desc = str_replace('<br/>',"\n",$desc);</textarea>
      </label>
    </form>
    Code (markup):

    so i have put
    $desc = str_replace('<br/>',"\n",$desc);
    PHP:
    into:

    <form name="form1" method="post" action="">
      <label>
      <textarea name="textarea" cols="30" rows="10"></textarea>
      </label>
    </form>
    PHP:
    but then in the text area it gives not the discription but:

    $desc = str_replace('<br/>',"\n",$desc);
    Code (markup):

    can someone please give me the correct code, please
     
    nevret2, Jun 9, 2008 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    I already told you the answer. You are using template system.

    So the code I gave you will go on a php file.

    Peace,
     
    Barti1987, Jun 9, 2008 IP
  6. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #6
    @azizny
    you haven't told the correct answer.
    you gave $desc = str_replace('<br/>',"\n",$desc);
    but nevret2 says 'what are those <br></br><br></br>?'
    the code you gave just replace '<br/>' tags not <br> or </br>.

    anyway..

    @nevret2

    maybe your problem could be something like that while the description data is being inserted into datababe, the htmlspecialchars function could translate the data into safe one.
    use
    <textarea name="textarea" cols="30" rows="10">htmlspecialchars_decode($desc)</textarea>

    maybe that could be the solution..

    let me know if it works.
     
    mehmetm, Jun 9, 2008 IP
  7. AFitch

    AFitch Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It's probably not in a PHP file, and he isn't initiating PHP by using <?php ?>

    You should definately not be asking questions until you understand the basics. He is treating it like HTML. Tutorials will do much better for you right now.

    Also, what he wants to do isn't even clear. Echo a variable? Replace line breaks? Both? Does he want pre-determined text in a form? Why? He could just physically put it there if it isn't going to change. Does he want that form to control $desc for later use?

    This Thread Is Worthless.
     
    AFitch, Jun 9, 2008 IP
  8. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #8
    That will not work. It will appear as it.

    He is using Template, how clear do I have to be?

    Peace,
     
    Barti1987, Jun 9, 2008 IP