Topic: insert dynamic values into text area

I am trying to insert some values into the different fields of an update form:

<table class="tablita2">
                          <tr>
                            <td><strong>Titulo:</strong> </td>
                            
                            <td><input name="titulo" type="text" size="40" maxlength="40" value="<?php echo $titulo; ?>"/>   </td>   
                          </tr>
                          <tr>
                            <td><strong>Fecha:</strong> </td>
                            <td><input name="fecha" type="text" size="40" maxlength="40" value="<?php echo $fecha; ?>" /></td>
                          </tr>
                          <tr>
                            <td><strong>Lugar:</strong> </td>
                            <td><input name="lugar" type="text" size="40" maxlength="40" value="<?php echo $lugar; ?>"/></td>
                          </tr>
                          <tr>
                            <td><strong>Hora:</strong> </td>
                            <td><input name="hora" type="text" size="40" maxlength="40" value="<?php echo $hora; ?>"/></td>
                          </tr>
                          <tr>
                            <td><strong>Comentarios:</strong> </td>
                            <td><textarea name="comentarios" cols="40" rows="3" ></textarea></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td><p>
                              <input type="submit" name="submit" value="Editar" />
                            </p>
                            <p>&nbsp; </p></td>
                          </tr>
                        </table>

The only one I have problems with is the text area. It doesn't work. Where should I put the "value"?

Thanks

Eduardo

Last edited by edoplaza (2009-11-04 22:57:58)

Re: insert dynamic values into text area

Where are you getting the values from?
a database look-up? or a form submission? an array of values?
Are the values defined in your code before you use them in this snippet?

When the client first uses the form, before the submission, are there default values set?

You should be using an 'if' statement to confirm the value isset() before attempting to echo them.
The 'if' can be where you have the php snippet now.

<td><input name="fecha" type="text" size="40" maxlength="40" value="<?php if isset($_POST['fecha'])  ? echo $fecha : echo 'default data'; ?>" /></td>

Re: insert dynamic values into text area

I don't believe the textarea has a "value" like the other inputs do, so this won't work:

<textarea name="comentarios" cols="40" rows="3" value="<?php echo $variable; ?>"></textarea>

You can, however, echo out your data between the opening and closing textarea tags:

<textarea name="comentarios" cols="40" rows="3"><?php echo $variable; ?></textarea>

Re: insert dynamic values into text area

It didn't work with "echo...". But it works with "print...":

<td><textarea name="comentarios" cols="40" rows="3" ><?php print $comentarios; ?></textarea></td>