views:

19

answers:

1

I building my own simple article management system, and have run into a bit of trouble upon creating a page to edit the articles.

I am able to recall the title and tagline of the articles in the form input using the 'value' attribute.

However, I am yet to work out how to do the same thing with the form textarea as it has no 'value' attribute.

Also, can the same be done with a dropdown menu in the HTML form select?

+1  A: 

The textarea input type does not have a value field, the value must be placed within the tag itself. For example:

<textarea>Here are the contents of the textarea</textarea>

To populate the select field, the syntax would be:

<select> <option value="value1">Value 1</option> </select>

Brandon Horsley
cheers, I have used the php echo to return the values in the input fields and have done as suggested for the textarea using a similar echo, but i get no data returned.Am I using incorrect php functions or something?
Stuart
can you post some of your php and the html it generates? you will probably also want to escape your output using htmlspecialchars.
Brandon Horsley
Here is my php from the body of the page (I'll post the form as a separate comment because its too big to all fit here):<?php....get files....// Create an instance of DbConnector$connector = new DbConnector();// Check whether a form has been submitted. If so, carry onif ($_POST){....Validate form...$insertQuery = "UPDATE cmsarticles (title,tagline,section,thearticle) VALUES ("."'".$_POST['title']."', "."'".$_POST['tagline']."', ".$_POST['section'].", "."'".addslashes($_POST['thearticle'])."')";.... save form....?>
Stuart
<form name="form1" method="post" action="<?php echo $PHP_SELF ?>"> <p> Title: <input name="title" type="text" id="title" value="<?php echo $row['title']; ?>"> </p> <p> Tagline: <input name="tagline" type="text" id="tagline" value="<?php echo $row['tagline']; ?>"> </p>
Stuart
<p> Section: <select name="section" id="section"> <?PHP // Generate a drop-down list of sections. // NOTE : Requires database modifications in article 4 $result = $connector->query('SELECT ID,name FROM cmssections ORDER BY name'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo $row['section']; echo '<option value="'.$row['ID'].'">'.$row['name'].'</option>'; } ?> </select> </p>
Stuart
<p> Article: <textarea name="thearticle" cols="50" rows="12" id="thearticle"><?php echo $row['thearticle']; ?></textarea> </p> <p align="center"> <input type="submit" name="Submit" value="Update"> </p> </form>
Stuart
I suspect your $row variable does not contain what you think it does. You can use var_dump($row) to view the contents.
Brandon Horsley