culldog88
culldog88

Reputation: 93

php pre-populating text area

The following php code works for prepopulating an input box, but doesn't work for a text area. The issue is that the standard input box is small in height so the text is displayed on one line. I tried to use the text area instead but it appears blank when rendered. The code shows both methods, the working method, followed by the text area method. Can anyone advise?

<?php
 echo "<form method='POST' action='edit.php'>
    <fieldset>
    <div class='form-group'>        
    <label for='descriptionField'>Description</label>

    **<input type='text' value='$description' class='form-control' name ='nameField'>**

    **<textarea class='form-control'value='$description' input type='text' rows='10' name ='descriptionField'></textarea>**   

    <input type='hidden' value='$id_data' name='idField'>
    <br>

  <input class='btn btn-success' type='submit' value='update'>
  </div>
  </fieldset>       
    </form>";
        }
    ?>

Upvotes: 0

Views: 303

Answers (2)

If you want to set a text areas input, you can simply put in in between the <textarea> tags like so in your example:

<textarea class='form-control' input type='text' rows='10' name ='descriptionField'>
    $description
</textarea>

Also refer to the w3schools article on the textarea tag for further details.

Upvotes: 0

msbomrel
msbomrel

Reputation: 519

Did you try like this?

<?php
     echo "<form method='POST' action='edit.php'>
        <fieldset>
        <div class='form-group'>        
        <label for='descriptionField'>Description</label>
    
        **<input type='text' value='$description' class='form-control' name ='nameField'>**
    
        **<textarea class='form-control' input type='text' rows='10' name ='descriptionField'>htmlspecialchars($description);</textarea>**   
    
        <input type='hidden' value='$id_data' name='idField'>
        <br>
    
      <input class='btn btn-success' type='submit' value='update'>
      </div>
      </fieldset>       
        </form>";
            }
        ?>

Upvotes: 2

Related Questions