Re,
Je t'ai fait un petit exemple pour t'aider à comprendre le principe.
Pour tester, copie les deux fichiers chez toi dans le même dossier, et ouvre un navigateur sur main.php
main.php
<?php
function __autoload($class_name) { require_once './'.$class_name.'.php'; }
session_start();
header('content-type: text/html charset=utf-8');
if(empty($_SESSION['textbox1'])) $_SESSION['textbox1'] = new TextBox('Bonjour');
if(empty($_SESSION['textbox2'])) $_SESSION['textbox2'] = new TextBox('PHPFrance');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<body>
<form action="./main.php" method="post">
<?php $_SESSION['textbox1']->render() ?>
<br/>
<?php $_SESSION['textbox2']->render() ?>
<br/>
<?php
echo htmlspecialchars(
$_SESSION['textbox1']->getValue().
' '.
$_SESSION['textbox2']->getValue()
, ENT_NOQUOTES, 'UTF-8'); ?>
<input type="submit" />
</form>
</body>
</html>
TextBox.php
<?php
class TextBox
{
private $_value;
private $_id;
public function __construct($value)
{
if(empty($_SESSION['ctr'])) $_SESSION['ctr'] = 0;
$this->_id = '_'.($_SESSION['ctr']++);
$this->_value = $value;
}
public function render()
{
$v = htmlspecialchars($this->_value, ENT_COMPAT, 'UTF-8');
echo <<<HTML
<input name="$this->_id" type="text" value="$v" />
HTML;
}
public function getValue() { return $this->_value; }
public function __wakeup()
{
if(array_key_exists($this->_id, $_POST))
$this->_value = get_magic_quotes_gpc() ? stripslashes($_POST[$this->_id]) : $_POST[$this->_id];
}
}
?>
Tracker.