Estimados
Requiero de su ayuda, estoy haciendo un formulario y me he roto la cabeza para ver su validación pero no lo logro.
Les pido una ayudita pliss, este es el código
Código php:
Código PHP:
if(isset($_POST['submit'])){
$errors = array();//declaramos un array para almacenar los errores
if($_POST['nombre'] ==''){
$errors[1] ='<span class="error">Ingrese su nombre</span>';
}else if($_POST['email'] =='' or !preg_match("/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/",$_POST['email'])){
$errors[2] ='<span class="error">Ingrese su email correcto</span>';
}else if($_POST['empresa'] ==''){
$errors[3] ='<span class="error">Ingrese una empresa</span>';
}else if($_POST['telefono'] ==''){
$errors[4] ='<span class="error">Ingrese su telefono</span>';
}else if($_POST['value'] === ''){
$_POST['value'] = NULL;
}else if($_POST['comment'] ==''){
$errors[5] ='<span class="error">Ingrese su mensaje</span>';
}else {//si todo esta ok envia email
HTML del FORM
Código PHP:
<form action="" method="post" class="contacto">
<div>
<label>Tu nombre:</label>
<input name='nombre' type='text' id='nombre' value='<?php echo $_POST['nombre']; ?>' size='40' class='nombre' />
<?php echo $errors[1]; ?></div>
<div>
<label>Tu email:</label>
<input name='email' type='text' id='email' value='<?php echo $_POST['email']; ?>' size='40' class='email' />
<?php echo $errors[2]; ?></div>
<div>
<label>Tu empresa o colegio:</label>
<input name='empresa' type='text' id='empresa' value="<?php echo $_POST['empresa']; ?>" size='40' class='empresa' />
<?php echo $errors[3]; ?></div>
<div>
<label>Tu teléfono:</label>
<input name='telefono' type="text" id='telefono' value="<?php echo $_POST['telefono']; ?>" size='40' class='telefono' />
<?php echo $errors[4]; ?></div>
<div class="referente">
<p>Tu pregunta es referente a:</p>
<table width="300" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><p><input type="radio" name="pregunta" value="Logistica_Retiro" id="Logistica_Retiro" />
logística y Retiro</p></td>
</tr>
<tr>
<td><p><input type="radio" name="pregunta" value="Marketing" id="Marketing" />
Campañas de reciclaje y Marketing</p></td>
</tr>
<tr>
<td><p><input type="radio" name="pregunta" value="FAQs" id="FAQs" />
FAQs</p></td>
</tr>
<tr>
<td><p><input type="radio" name="pregunta" value="news" id="news" />
Noticias</p></td>
</tr>
</table>
</div>
<div>
<p>Como nos conocio:</p>
<select name="conoce" class="conoce" id="conoce" onchange="onSelectChange();" >
<option value="" selected>----------</option>
<option value="Buscador Web">Por un buscador</option>
<option value="Blog">Por un Blog</option>
<option value="Referencia">Por referencias</option>
<option value="Otros">Otro</option>
</select>
<!--<div class="errors error3"></div>-->
</div>
<div>
<label>Mensaje:</label>
<textarea name='comment' cols="60" rows='6' class="comment" id='comment'><?php echo $_POST['comment']; ?></textarea>
<?php echo $errors[5]; ?></div>
<div><input name='submit' type='submit' class='button' id='submit' value='Envia Mensaje'></div>
<?php echo $result; ?>
</form>