PHP - Ayuda con formulario php & html

 
Vista:

Ayuda con formulario php & html

Publicado por Leslie (1 intervención) el 21/02/2018 17:37:34
hola alguien me puede ayudar con esto..... Estoy haciendo un formulario en html y en php. Al cargarlo a mi servidor de pruebas no me esta funcionando correctamente....

Me arroja el siguiente error: Mensaje no válido, por favot intentelo de nuevo.

Adjunto los archivos, y la web. Espero alguien de con la solución correcta. Gracias!

EL 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<style>
 
#formulario {
  width:auto;
  height: 200px;
  position: relative;
  margin: 0 auto;
}
#formulario .header {
  background-color: #fff;
  background-repeat: no-repeat;
  background-position: center;
  height: 83px;
  text-indent: -9999px;
}
#formulario .body {
  height: auto;
  background-color: rgba(284,284,284,0);
  background-repeat: no-repeat;
  background-position: center;
  overflow: hidden;
  padding: 15px;
}
#formulario .body label {
  height: 37px;
  width:80px;
  text-align: center;
  display: inline-block;
  color: #000066;
  background-color: #fff;
  font-size: 12px;
  line-height: 15px;
  margin: 7px 0;
  padding: 0 7px 0 0;
  border: none;
  border-radius:5px;
  vertical-align: top;
}
 
#formulario .body input[type=text]{
  vertical-align: top;
  width: 200px;
  height: 37px;
  background-color: rgba(0, 0, 2, 0.2);
  border: none;
  display: inline-block;
  margin: 7px 0;
  padding: 3px 10px;
  font-family: "daxcompact-regularregular", arial, sans-serif;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.7);
  -moz-transition: all 100ms ease-in-out;
  -o-transition: all 100ms ease-in-out;
  -webkit-transition: all 100ms ease-in-out;
  transition: all 100ms ease-in-out;
}
 
#formulario .body textarea{
vertical-align: top;
  width: 200px;
  height: 50px;
  background-color: rgba(0, 168, 254, 1);
  border: none;
  display: inline-block;
  margin: 7px 0;
  padding: 3px 10px;
  font-family: "daxcompact-regularregular", arial, sans-serif;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.7);
  -moz-transition: all 100ms ease-in-out;
  -o-transition: all 100ms ease-in-out;
  -webkit-transition: all 100ms ease-in-out;
  transition: all 100ms ease-in-out;
 
}
#formulario .body input[type=text]:active, #formulario .body input[type=text]:focus, #formulario .body input[type=text]:hover  {
  color: white;
  background-color: rgba(0, 0, 0, 0.4);
}
#formulario .body input#telefono {
  width: 157px;
}
#formulario .body input.long {
  width: 667px;
}
#formulario .body select {
  -moz-appearance: none;
  -webkit-appearance: none;
  -ms-appearance: none;
  -o-appearance: none;
  appearance: none;
  display: inline-block;
  width: 162px;
  margin: 7px 0;
  border-radius: 0;
  cursor: pointer;
  background-position: 135px center;
  background-repeat: no-repeat;
  background-size: 15px;
}
 
#formulario .body .preg {
  width: 667px;
  text-align: left;
  margin: 4px auto 0px;
  padding: 0 3px;
  color: #FFFFFF;
  font-family: "sf_movie_poster", arial, sans-serif;
  text-transform: lowercase;
  font-size: 29px;
  letter-spacing: 2px;
  line-height: 20px;
}
#formulario .body .right {
  width: 667px;
  margin: 0 auto;
  text-align: right;
}
#formulario .body button.send {
  display: inline-block;
  background: -webkit-linear-gradient(#333, #101010);
  background: -moz-linear-gradient(#333, #101010);
  background: -o-linear-gradient(#333, #101010);
  background: -ms-linear-gradient(#333, #101010);
  background: linear-gradient(#333333, #101010);
  border: 1px solid #101010;
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.1);
  height: 37px;
  width: 120px;
  margin: 15px 0 15px 15px;
  text-align: center;
  font-family: "sf_movie_poster", arial, sans-serif;
  text-transform: uppercase;
  font-size: 15px;
  letter-spacing: 3px;
  line-height: 18px;
  color: #FFFFFF;
  cursor: pointer;
}
#formulario .body button.send span {
  font-size: 16px;
  line-height: 30px;
}
#formulario .body button.send:hover {
  background: -webkit-gradient(linear, 0 0, 0 100%, from(#444), to(#151515));
  background: -webkit-linear-gradient(#444, #151515);
  background: -moz-linear-gradient(#444, #151515);
  background: -o-linear-gradient(#444, #151515);
  background: linear-gradient(#444444, #151515);
}
#formulario .body button.send:active {
  box-shadow: inset 0 2px 7px 3px rgba(0, 0, 0, 0.5);
}
#formulario .body button.send[disabled], #formulario .body button.send[disabled]:hover, #formulario .body button.send[disabled]:active, #formulario .body button.send[disabled]:focus {
  background: -webkit-linear-gradient(#333, #555);
  background: -moz-linear-gradient(#333, #555);
  background: -o-linear-gradient(#333, #555);
  background: -ms-linear-gradient(#333, #555);
  background: linear-gradient(#333333, #555555);
  border: 1px solid #333;
}
#formulario .body .pop {
  display: block;
  position: absolute;
  height: 525px;
  width: 700px;
  left: 50%;
  margin-left: -350px;
  top: 130%;
  z-index: 10;
  background-color: rgba(255, 255, 255, 0.95);
  background-position: center 150px;
  background-repeat: no-repeat;
  font-family: "sf_movie_poster", arial, sans-serif;
  font-size: 65px;
  line-height: 0.9;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding-top: 270px;
  color: #99ccff;
  box-shadow: 0 10px 30px 4px rgba(0, 0, 0, 0.25);
  -moz-transition: top 1s ease-in-out;
  -o-transition: top 1s ease-in-out;
  -webkit-transition: top 1s ease-in-out;
  transition: top 1s ease-in-out;
}
#formulario .body .pop.activo {
  top: 20px;
}
#formulario .footer {
  padding: 20px;
  min-height: 60px;
  line-height: 1.1;
  background: #272727;
  text-align: center;
  color: #99ccff;
  font-family: "daxcompact-regularregular", arial, sans-serif;
}
#formulario .footer .small {
  margin: 0 auto;
  padding: 20px 55px 0;
  font-size: 11px !important;
  color: #a8a8a8;
  line-height: 1.5;
  text-align: left;
}
 
#formulario input[type=text][disabled], #formulario select[disabled], #formulario button[disabled] {
  background-color: rgba(128, 128, 128, 0.3);
  color: #ccccff;
}
#formulario input[type=text][disabled]:hover, #formulario input[type=text][disabled]:active, #formulario input[type=text][disabled]:focus, #formulario select[disabled]:hover, #formulario select[disabled]:active, #formulario select[disabled]:focus, #formulario button[disabled]:hover, #formulario button[disabled]:active, #formulario button[disabled]:focus {
  color: #333;
  background-color: rgba(128, 128, 128, 0.3);
}
</style>
 
 
<form id="formulario" method="post" action="gracias.php">
 
    <div class="body">
    <label for="nombre" name="nombre">Nombre:</label>
 
    <input type="text" id="nombre" spellcheck="false" name="nombre" autocomplete="off" />
 
    <label for="lada" name="lada">Lada:</label>
 
    <input type="text" id="lada" spellcheck="false" name="lada" autocomplete="off" />
 
    <label for="tel" name="tel">Teléfono</label>
 
    <input type="text" name="tel" spellcheck="false" autocomplete="off" />
 
    <label for="email" name="email">Email:</label>
 
    <input type="text" id="email" spellcheck="false" name="email" autocomplete="off" />
 
    <label for="pasajeros" name="pasajeros">Cantidad de pasajeros:</label>
 
     <input type="text" id="pasajeros" spellcheck="false" name="pasajeros" autocomplete="off" />
 
    <label for="destino" name="destino">Destino:</label>
 
     <input type="text" id="destino" spellcheck="false" name="destino" autocomplete="off" />
 
    <label for="hora" name="hora">¿A que hora salen y a que hora regresan?:</label>
 
    <input type="text" id="hora" spellcheck="false" name="hora" autocomplete="off" />
 
     <label for="fecha" name="fecha">Fecha exacta del servicio:</label>
 
     <input type="text" id="fecha" spellcheck="false" name="fecha" autocomplete="off" />
 
    <label for="itinerario" name="itinerario">Itinerario:</label>
 
    <input type="text" id="itinerario" spellcheck="false" name="itinerario" autocomplete="off" />
 
    <br>
    <button class="send">Enviar</button>
    </div>
 
</form>



EL PHP

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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
 
if(isset($_POST['email'])) {
 
 
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "shaigroup@gmail.com,ventas@smartbuses.mx";
 
    $email_subject = "Formulario Smart Buses Movil";
 
 
 
 
 
    function died($error) {
 
        // your error code can go here
 
        echo "Lo sentimos mucho , pero había un error(s) encontrado en el formulario que ha enviado.";
 
        echo "Estos errores aparecen a continuación.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Por favor intentalo de nuevo <br /><br />";
 
        die();
 
    }
 
 
 
    // validation expected data exists
 
    if(!isset($_POST['nombre']) ||
 
        !isset($_POST['email']) ||
 
		!isset($_POST['lada']) ||
 
        !isset($_POST['tel']) ||
 
        !isset($_POST['pasajeros']) ||
 
		!isset($_POST['destino']) ||
 
		!isset($_POST['hora']) ||
 
		!isset($_POST['fecha']) ||
 
		!isset($_POST['itinerario'])) {
 
        died('Algo falto');
 
    }
 
 
    $nombre = $_POST['nombre']; // required
 
    $email_from = $_POST['email']; // required
 
	$lada = $_POST['lada']; // not required
 
    $tel = $_POST['tel']; // required
 
    $pasajeros = $_POST['pasajeros']; // required
 
	$destino = $_POST['destino']; // required
 
	$hora = $_POST['hora']; // required
 
	$fecha = $_POST['fecha']; // required
 
	$itinerario = $_POST['itinerario']; // required
 
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'Email no valido <br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$nombre)) {
 
    $error_message .= 'Nombre no valido <br />';
 
  }
 
 
  if(strlen($mensaje) < 2) {
 
    $error_message .= 'Mensaje no valido <br />';
 
  }
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Formulario Smart Buses Movil\n\n";
 
 
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
 
 
    $email_message .= "Nombre: ".clean_string($nombre)."</br>";
 
    $email_message .= "Email: ".clean_string($email_from)."</br>";
 
	$email_message .= "Lada: ".clean_string($email_from)."</br>";
 
    $email_message .= "Teléfono: ".clean_string($tel)."</br>";
 
    $email_message .= "Pasajeros: ".clean_string($pasajeros)."</br>";
 
	$email_message .= "Destino: ".clean_string($destino)."</br>";
 
	$email_message .= "Hora: ".clean_string($hora)."</br>";
 
	$email_message .= "Fecha: ".clean_string($fecha)."</br>";
 
	$email_message .= "Itinerario: ".clean_string($itinerario)."</br>";
 
 
 
// create email headers
 /*
$headers = 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n" .
 
'X-Mailer: PHP/' . phpversion();
 
mail($email_to, $email_subject, $email_message, $headers);
*/
$headers = "MIME-Version: 1.0 \n";
$headers .= "Content-Type: text/html; charset=UTF-8\n";
$headers .= "From: \"".$email_from."\" <$email_from>\n";
 
mail($email_to, $email_subject, $email_message, $headers);
 
?>
<script>
	window.location="http://smartbuses.mx/phone/gracias.html";
</script>
<?php
 
}
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro
Val: 1.634
Plata
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Ayuda con formulario php & html

Publicado por Alejandro (840 intervenciones) el 22/02/2018 17:30:10
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
¬_¬ $mensaje no esta definida por lo tanto simpre sera 0 y la condicion 0<2 se cumple
1
2
3
if(strlen($mensaje) < 2) {
     $error_message .= 'Mensaje no valido <br />';
  }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar