Problema con formulario
Publicado por Sergio (112 intervenciones) el 11/06/2016 11:57:20
Buenos días a todos, tengo un archivo php que se llama nuevo_plato.php en el que hay un formulario y su validación en el mismo archivo, pero que NO FUNCIONA!!!!!!. Cuando mando el formulario, con los campos de texto vacíos, me tendría que salir un mensaje de que los campos están vacíos, pero lo único que hace es volver a cargar el formulario. Os pongo el código a ver si me podéis ayudar. Gracias de antemano.
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Administración Cafetería Tonik</title>
<link href="estilos.css" rel="stylesheet" type="text/css">
<style type="text/css">
#apDiv1 {
position: absolute;
width: 422px;
height: 316px;
z-index: 1;
left: 321px;
top: 148px;
border-top-width: thin;
border-right-width: thin;
border-bottom-width: thin;
border-left-width: thin;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
box-shadow: 5px 5px 5px #3333CC;
}
#apDiv2 {
position: absolute;
width: 405px;
height: 274px;
z-index: 2;
left: 332px;
top: 160px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
border-top-width: thin;
border-right-width: thin;
border-bottom-width: thin;
border-left-width: thin;
}
label {
font-family:"Times New Roman", Times, serif;
font-size:18px;
}
input {
background-color:#039;
color:#FFF;
width:250px;
height:20px;
font-family:"Times New Roman", Times, serif;
font-size:18px;
}
textarea {
background-color:#039;
color:#FFF;
width:370px;
font-family:"Times New Roman", Times, serif;
font-size:18px;
}
#precio {
background-color:#039;
color:#FFF;
width:50px;
height:20px;
font-family:"Times New Roman", Times, serif;
font-size:18px;
}
#btn_entrar {
background-color:#666;
color:#000;
width: 80px;
height: 40px;
cursor:pointer;
color:#FFF;
text-shadow: rgb(0,0,150) 3px 3px 5px;
font-family:"Times New Roman", Times, serif;
font-size:20px;
}
body {
background: -webkit-linear-gradient(20deg, #FFF, #03F);
background: -moz-linear-gradient(20deg, #FFF, #03F);
background: -o-linear-gradient(20deg, #FFF, #03F);
background: linear-gradient(20deg, #FFF, #03F);
}
#apDiv3 {
position: absolute;
width: 690px;
height: 115px;
z-index: 3;
left: 233px;
top: 5px;
text-align:center;
font-family:"Times New Roman", Times, serif;
font-size:36px;
color:#FFF;
text-shadow: rgb(0,0,150) 3px 3px 3px;
}
</style>
</head>
<body>
<div id="apDiv1"></div>
<div id="DivLogo">Cafetería Tonik Administración</div>
<div id="apDiv2">
<form method="post" action="nuevo_plato.php">
<p>
<label for="titulo">Título del plato:</label>
<input name="titulo" type="text" id="titulo">
</p>
<p>
<label for="plato">Plato:</label>
</p>
<p>
<textarea name="plato" rows="4" cols="60"></textarea>
</p>
<p>
<label for="precio">Precio del plato:</label>
<input type="number" name="precio" id="precio" class="precio" step="any">
</p>
<p align="center">
<input id="btn_entrar" type="submit" value="Guardar" name="btn_entrar">
</p>
</form>
</div>
</body>
</html>
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
<?php
include ("../cafeteria_tonik_conexion.php");
session_start();
if (isset($_GET['id_mio']))
{
$identificador = $_GET['id_mio'];
echo $identificador;
}
if (isset($_POST['btn_entrar']))
{
$titulo = $_POST['titulo'];
$plato = $_POST['plato'];
$precio = $_POST['precio'];
if (empty($plato))
{
echo "<script language='JavaScript'>
alert('Debes introducir un plato');
document.location=('nuevo_plato.php');
</script>";
header('Location: nuevo_plato.php');
}
if (empty($precio))
{
echo "<script language='JavaScript'>
alert('Debes introducir un precio para este plato');
document.location=('nuevo_plato.php');
</script>";
header('Location: nuevo_plato.php');
}
}
?>
Valora esta pregunta


0