Jump to content

Problem with PHP and form's textarea: $_POST not returning values


frankienrg

Recommended Posts

The Form:

 

<form action="pagina5.php" method="post">
<table align="center" width="500">
<tr><td align="right">Nome:</td><td><input type="text" maxlength="35" size="35" name="nome" /><td></tr>
<tr><td align="right">E-mail:</td><td><input type="text" maxlength="40" size="35" name="email" /><td></tr>
<tr><td align="right">Voto:</td><td><select name="voto"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option selected="selected" value="5">5</option></select><td></tr>
<tr><td align="center" colspan="2"> *Commento:</td></tr>
<tr><td align="center" colspan="2"><textarea rows="7" cols="50" name="commento"></textarea></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="invia" value="Invia"><input type="reset" value="Resetta"></td></tr>
<tr><td align="center" colspan="2"><a href="gb.php">Torna Indietro</a></td></tr>
<tr><td align="center" colspan="2"><br/><br/>* = Campi Obbligatori</td></tr>
</table>
</form>

 

the script (pagina5.php):

<?
if (isset($_POST['invia']))
{
if((!isset($_POST['commento'])) OR ($_POST['commento']=""))
{
	echo "<p align='center'>Non hai compilato i campi richiesti!</p>";
	echo "<p align='center'><br/><a href='gb.php'>Torna Indietro</a></p>";
}
else
{
var_dump($_POST['nome']);
var_dump($_POST['email']);
var_dump($_POST['commento']);
var_dump($_POST['voto']);
//var_dump($x);
echo "<p align='center'><br/><a href='gb.php'>Torna Indietro</a></p>";
}
}
?>

 

vardumps work correctly for any value except the textarea (commento).

 

It skips the if (!isset) check, too.

 

I tried using an ID, too, couldn't get it to work

I'm at a lost here, please help, fellow coders.

You are not using a comparison operator when checking $_POST['commento'] = "".  Instead, you are emptying it.

 

Change

 

if((!isset($_POST['commento'])) OR ($_POST['commento']=""))

 

to*

 

if (!isset($_POST['commento']) || empty($_POST['commento']))

 

*just cleaned it up a bit, too.

 

However, this is the correction to your original issue:

 

if((!isset($_POST['commento'])) OR ($_POST['commento']==""))

 

Note the == which is checking if $_POST['commento'] is of any length.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.