Ragazzi considerate lo script che vi posto... serve per inserire dati nome e cognome, se non viene inserito il cognome ad esempio compare il messaggio di errore ma mantiene la stringa nome in modo tale che l utente non dovrà ridigitarla...ad ogni visualizzazione però mi aggiunge uno spazio e dunque la stringa non risulta vuota!!! non capisco proprio perchè![]()
<head>
<title>Pagina di prova</title>
</head>
<body>
<?php
if (isset($_POST['submit']))
{$surname=$_POST['surname'];
$firstname=$_POST['firstname'];
if($firstname =="") $firstErr=1;
else $firstErr=0;
if($surname=="") $surErr=1;
else $surErr=0;
}
else{
$firstErr=0;
$surErr=0;
$firstname="";
$surname="";
}
?>
<form action='<?php echo($_SERVER['PHP_SELF'])?>' method='post'>
<h2>Inserire i proprio dati personali </h2>
Nome : <input type='text' name='firstname' value='<?php echo($firstname)?> '>
<?php if ($firstErr) echo("<font color='red' size='2'> Inserire il nome </font>");
?>
Cognome : <input type='text' name='surname' value='<?php echo($surname)?> '>
<?php if ($surErr) echo("<font color='red' size='2'> Inserire il cognome </font>");
?>
<input type='submit' name='submit'>
</form>
</body>
</html>