In the following code-

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<form id="form1" name="form1" method="post" action="<?php echo($_SERVER['PHP_SELF']);?>">

      <input type="text" name="txt" id="txt" value="<?php $_POST['txt'];?>" />
    <input type="submit" name="b1" id="b1" value="Submit" />

<hr />

//form handler

					echo("Enter a value");



in this form, i am not able to understand why we have to use the value attribute for the textfield-

<input type="text" name="txt" id="txt" value="<?php $_POST['txt'];?>" />

don't we know that the $_POST variable refers to the value of the textfield? so why set the value attribute again?

Actually that code does nothing. It should be

<?php echo $_POST['txt'] ?>

Anyway, the reason that it would have been in there is if there was validation happening on that page then the forms would be repopulated so a user would not have to re-type.

This question has already been answered. Start a new discussion instead.