If I submit an opinion about a reservation and the textarea of opinion is empty, you should not allow the opinion to be sent.
The problem is that although it is empty if it accepts the spaces as a " opinion ", because it does not recognize it as empty. (empty).
You should only be allowed to submit the opinion if you have a minimum of 5-10 characters or at least have a letter type, not counting spaces (because the spaces counts them as text).
Code:
echo "<textarea rows='4' cols='56' id='texto_opinion' name='texto_opinion'></textarea>";
echo "<input type='submit' name='add_opinion' id='add_opinion' value='Añadir opinión'>";
if(isset($_POST["add_opinion"])){
if(isset($_POST['texto_opinion']) && !empty($_POST['texto_opinion'])){
$idemail = $cliente;
$idcabana = $_POST["a_anadir"];
$opinion = $_POST["texto_opinion"];
$fecha = new DateTime();
$fecha_hoy = $fecha->format ('Y/m/d');
$valoracion = isset($_POST["estrellas"])?$_POST["estrellas"]: "0"; //Sin marcar estrellas, valoracion=0.
BD::insertarOpinionPorReserva($idemail, $idcabana, $opinion, $fecha_hoy, $valoracion);
}else{
echo '<script language="javascript">alert("¡Debes escribir una opinión!");</script>';
}
}