I wanted to know if someone could give me a hand with this form that basically when you do not enter the required fields it refreshes in the same html. The subject that I always get this error
Warning: Can not modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/redirigitalmismo.php:6) in /Applications/MAMP/htdocs/redirigitalmismo.php on line 16
and I do not know how to solve it. It's supposedly because I'm sending information before the header. Thank you very much
<?php
ob_start();
?>
<?php
$errores = array();
if($_POST){
if(!trim($_POST['nombre'])) {
$errores['nombre'] = 'Debe ingresar un nombre';
}
if(!trim($_POST['email'])) {
$errores['email'] = 'Debes ingresar un mail';
}
if(!$errores) {
header('Location: http://www.google.com');
exit();
}
};
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<form action="" name="formulario" method="POST">
<input type="text" name="nombre" id="nombre" maxlength="30" onfocus="fondoColor(this)" placeholder="Tu nombre">
<?php if(isset($errores['nombre'])) { echo '<div>No pusiste Nombre</div>'; } ?>
<br>
<input type="email" name="email" value="" placeholder="Tu Mail">
<?php if(isset($errores['email'])) { echo '<div>No ingresaste Mail</div>'; } ?>
<br>
<input type="radio" name="sexo" id="Hombre"value="Hombre"> Hombre
<input type="radio" name="sexo" id="Mujer"value="Mujer"> Mujer
<br>
<input type="checkbox" name="terminos[]" id="terminos" value="uno" > Terminos y condiciones
<br>
<input type="checkbox" name="terminos[]" id="terminos" value="dos"> Mas terminos y condiciones
<br>
<input type="submit" name="btn" value="Enviar" id="btn">
</form>
</body>
</html>
<?php
ob_end_flush();
?>