Page 1 of 1

Textarea form data will not display

Posted: Sun Feb 12, 2012 2:19 pm
by rick.emmet
Hi Everyone,
I have an interface that users will view to see data that they are uploading to a site. I'm using echo statements to dump the form data (as $_SESSION variables) on the page, which works just fine in the “static” portion of the page. I want to allow the users to edit the data and so have a hidden form at the bottom of the page, where they can edit the form data.

Again, I'm using echo statements to in the form - value=“<?php echo $_SESSION['variable'] ?>” - to dump the values the user input. This works with every type of input except with a <textarea> field (its just blank). If I view the page source, I can see all the text that was entered in the text box (and passed as a session variable to the page, but it will not display. Here's a simplified verson the code (for the form):

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Page</title>
</head>
<body>
<form method="post" action="test_formView.php" name="form1" ID="form1" >
<label>Bake style</label>
<select name="Bstyle" id="Bstyle">
  <option>Broil</option>
  <option>High Temp</option>
  <option>Medium Temp</option>
  <option>Low Temp</option>
  <option>Warm</option>
</select><br />
<label>Oven</label>
<input name="Oven" type="text"  size="50" maxlength="80"  /><br />
<label>Baking <br> Description</label>
<textarea name="description" cols="45" rows="5"  id="description"  ></textarea><br />
<label></label><input type="submit" name="userfile" value="Submit Info" />
</form>
</body>
And here's a simplified version of the php code that processes the form data:

Code: Select all

<?php
	// code here for header, ect.
	
	// code to filter form data

	// storing POST variables in the session variable array
	$_SESSION['Bstyle'] = $_POST['Bstyle'];
	$_SESSION['Oven'] = $_POST['Oven'];
	$_SESSION['description'] = $_POST['description'];

	// Show the user what the contents of the ad uploaded
?>
<form method="post" action="test_formView.php" name="form1" ID="form1" >
<label>Bake style</label>
<select name="Bstyle" id="Bstyle">
  <option><?php echo $_SESSION['Bstyle'] ?></option>
  <option>Broil</option>
  <option>High Temp</option>
  <option>Medium Temp</option>
  <option>Low Temp</option>
  <option>Warm</option>
</select><br />
<label>Oven</label>
<input name="Oven" type="text"  size="50" maxlength="80" value="<?php echo $_SESSION['Oven'] ?>" /><br />
<label>Baking <br> Description</label>
<textarea name="description" cols="45" rows="5"  id="description" 
  value="<?php echo $_SESSION['description'] ?>" ></textarea><br />
<label></label><input type="submit" name="userfile" value="Re-submit Info" />
</form>

<?php
	// code here for footer
?>
When I submit the form, the processing page displays the form again (this is slightly different than the original way i'm doing this) with the data dynamically placed in the form. This allows the user to edit the form. All the data is displayed except the textarea data, that text box remains empty (although the data can be seen in the page source code). Can anyone explain why this is happening and how to fix it? I'd like to know! I appreciate your time.
Cheers,
Rick

Re: Textarea form data will not display

Posted: Fri Feb 17, 2012 11:44 am
by rick.emmet
Hi Everyone,
I have a solution - this is rather banal (I couldn't think of something so simple). I simply had to move the code <?php echo $_SESSION['discription']; ?> in between the <textarea> and </textarea> tags - works great.

Code: Select all

<textarea name="description" cols="45" rows="5" id="description" > <?php echo $_SESSION['discription']; ?> </textarea>
Hope this helps others!
Cheers,
Rick