
Validar select dinamico
Publicado por ticosejo (4 intervenciones) el 03/03/2015 18:16:18
Buenas:
Estoy haciendo un formulario en el que hay un select dinámico y que, a la hora de enviarlo me arroja el siguiente error:
Notice: Undefined index: tipos in C:\xampp\htdocs\formcont2\index.php on line 13
en vez de validarme el select saltándome el error "Escoja una opción"
¿Que puede estar pasando? La variable tipos está definida
Gracias
Estoy haciendo un formulario en el que hay un select dinámico y que, a la hora de enviarlo me arroja el siguiente error:
Notice: Undefined index: tipos in C:\xampp\htdocs\formcont2\index.php on line 13
en vez de validarme el select saltándome el error "Escoja una opción"
¿Que puede estar pasando? La variable tipos está definida
Gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require('conexion.php');
if(isset($_POST['boton'])){
if($_POST['nombre'] == ''){
$error1 = '<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'])){
$error2 = '<span class="error">Ingrese un email correcto</span>';
}else if($_POST['asunto'] == ''){
$error3 = '<span class="error">Ingrese un asunto</span>';
}else if($_POST['mensaje'] == ''){
$error4 = '<span class="error">Ingrese un mensaje</span>';
}else if($_POST['tipos'] == ''){
$error5 = '<span class="error">Escoja una opción</span>';
}else{
$dest = "tu@email.com"; //Email de destino
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$asunto = $_POST['asunto']; //Asunto
$cuerpo = $_POST['mensaje']; //Cuerpo del mensaje
//Cabeceras del correo
$headers = "From: $nombre <$email>\r\n"; //Quien envia?
$headers .= "X-Mailer: PHP5\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //
if(mail($dest,$asunto,$cuerpo,$headers)){
foreach($_POST AS $key => $value) {
$_POST[$key] = mysql_real_escape_string($value);
}
$sql = "INSERT INTO `cf` (`nombre`,`email`,`usuario`,`tipo`,`asunto`,`mensaje`) VALUES ('{$_POST['nombre']}','{$_POST['email']}','{$_POST['usuarios']}','{$_POST['tipos']}','{$_POST['asunto']}','{$_POST['mensaje']}')";
mysql_query($sql) or die(mysql_error());
$result = '<div class="result_ok">Formulario enviado correctamente </div>';
// si el envio fue exitoso reseteamos lo que el usuario escribio:
$_POST['nombre'] = '';
$_POST['email'] = '';
$_POST['asunto'] = '';
$_POST['mensaje'] = '';
}else{
$result = '<div class="result_fail">Hubo un error al enviar el mensaje <img src="http://web.tursos.com/wp-includes/images/smilies/icon_sad.gif" alt=":(" class="wp-smiley"> </div>';
}
}
}
?>
<html>
<head>
<title>Contacto</title>
<link rel='stylesheet' href='estilos.css'>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
<script src='funciones.js'></script>
</head>
<body>
<form name='classic' class='contacto' method='POST' action=''>
<div><label>Tu Nombre:</label><input type='text' class='nombre' name='nombre' value='<?php if(isset($_POST['nombre'])){ echo $_POST['nombre']; } ?>'><?php if(isset($errors)){ echo $errors[1]; } ?></div>
<div><label>Tu Email:</label><input type='text' class='email' name='email' value='<?php if(isset($_POST['email'])){ $_POST['email']; } ?>'><?php if(isset($errors)){ echo $errors[2]; } ?></div>
<div><label>Asunto:</label><input type='text' class='asunto' name='asunto' value='<?php if(isset($_POST['asunto'])){ $_POST['asunto']; } ?>'><?php if(isset($errors)){ echo $errors[3]; } ?></div>
<div><label>Mensaje:</label><textarea rows='6' class='mensaje' name='mensaje'><?php if(isset($_POST['mensaje'])){ $_POST['mensaje']; } ?></textarea><?php if(isset($errors)){ echo $errors[4]; } ?></div>
<?php if(isset($errors)){ echo $errors[5]; } ?>
<select name="usuarios" size="4" onChange="updatetipos(this.selectedIndex)" style="width: 150px">
<option selected>Tipo Usuario</option>
<option value="personal">Personal</option>
<option value="estudiante">Estudiante</option>
<option value="otro">Otro</option>
</select>
<select name="tipos" size="4" style="width: 150px" >
</select>
<div><input type='submit' value='Envia Mensaje' class='boton' name='boton'></div>
<?php if(isset($result)) { echo $result; } ?>
</form>
<script type="text/javascript">
var usuarioslist=document.classic.usuarios
var tiposlist=document.classic.tipos
var tipos=new Array()
tipos[0]=""
tipos[1]=["Profesor|profesor", "Trabajador|trabajador"]
tipos[2]=["ADE|adev", "II|ii"]
tipos[3]=["Otro|otro"]
function updatetipos(selectedtipogroup){
tiposlist.options.length=0
if (selectedtipogroup>0){
for (i=0; i<tipos[selectedtipogroup].length; i++)
tiposlist.options[tiposlist.options.length]=new Option(tipos[selectedtipogroup][i].split("|")[0], tipos[selectedtipogroup][i].split("|")[1])
}
}
</script>
</body>
</html>
Valora esta pregunta


0