PHP - Como hago que los campos SEAN TODOS OBLIGATORIOS PARA CONTESTAR UNA ENCUESTA

 
Vista:

Como hago que los campos SEAN TODOS OBLIGATORIOS PARA CONTESTAR UNA ENCUESTA

Publicado por Elisabeth (1 intervención) el 10/07/2014 15:51:45
Hola, tengo este formulario y necesito que todos los campos sean obligatorios al mandar la encuesta, que no se olviden ninguna pregunta, me saben decir que cambio debo hacer? Desde ya muchas 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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Encuesta Hotel xxx :.</title>
<meta name="keywords" content="Formulario encuesta">
<style type="text/css">
.Estilo57 {font-size: 11px}
.Estilo62 {color: #FFFFFF}
.Estilo71 {	font-size: 12px;
	color: #008383;
}
.Estilo76 {	font-size: 12px;
	font-weight: bold;
	color: #008383;
}
.Estilo80 {	color: #008383;
	font-weight: bold;
}
.Estilo82 {	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: normal;
	color: #008383;
}
body,td,th {
	font-family: Tahoma, Geneva, sans-serif;
	color: #008383;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
	background-color: #F0EFEC;
}
body {
	background-color: #E9E6E1;
	margin-top: 0px;
	margin-bottom: 0px;
}
</style>
</head>
 
 
<body>
 
<body>
<table width="1003" bgcolor="#00A6A6" border="0" align="center">
  <tr>
    <td width="997" height="944" align="center" valign="top"><div id="wrapper2">
      <div id="content2">
        <div id="col2">
          <form method="post" action="encuesta.php">
 
<script languaje="javascript">
function habilita(form)
{
form.intereses[0].disabled = false;
form.intereses[1].disabled = false;
form.intereses[2].disabled = false;
}
 
function deshabilita(form)
{
form.intereses[0].disabled = true;
form.intereses[1].disabled = true;
form.intereses[2].disabled = true;
}
</script>
            <p><img src="logo.png" width="206" height="194" /></p>
            <p><br />
              <strong>INFORMACION DE CONTACTO</strong><br />
            </p>
            </p>
            <table width="612" border="0" align="center">
              <tr>
                <td width="597"><table width="460" border="0" align="center" cellpadding="5" cellspacing="5">
                  <tr>
                    <td width="118" align="right"><div align="left"><span class="Estilo82">Tu Nombre:</span></div></td>
                    <td width="307"><span class="Estilo57"><font face="Cambria"><b>
                      <input type="text" name="Nombre" size="52" id="Nombre" />
                    </b></font></span></td>
                    </tr>
                  <tr>
                    <td align="right"><div align="left"><span class="Estilo82">Tu Email:</span></div></td>
                    <td><span class="Estilo57"><font face="Cambria"><b>
                      <input type="text" name="E-mail" size="52" id="E-mail" />
                      </b></font></span></td>
                    </tr>
                  <tr>
                    <td align="right"><div align="left"><span class="Estilo82">Ciudad / Pais:</span></div></td>
                    <td><span class="Estilo57"><font face="Cambria"><b>
                      <input type="text" name="Ciudad" size="52" id="Ciudad" />
                      </b></font></span></td>
                    </tr>
                  </table></td>
              </tr>
          </table>
            <br />
            <hr color="#CCCCCC" size="1" width="96%" />
            <br />
            <strong>ENCUESTA</strong><br />
            <br />
            <table width="547" border="0" align="center" cellpadding="5" cellspacing="5">
              <tr>
                <td colspan="3" align="left"><strong>1. Habitación:</strong></td>
              </tr>
              <tr>
                <td align="left" class="Estilo82"><strong>¿Encontro usted su habitación:</strong></td>
                <td align="center"><strong>SI</strong></td>
                <td align="center"><strong>NO</strong></td>
              </tr>
              <tr>
                <td width="357" align="left"><span class="Estilo82">Confortable?</span></td>
                <td width="70" align="right"><div align="center">
                  <input type="radio" name="HABITACION_CONFORTABLE?" value="si" onclick="habilita(this.form)" />
                </div></td>
                <td width="70"><div align="center">
                  <input type="radio" name="HABITACION_CONFORTABLE?" value="no" onclick="deshabilita(this.form)" />
                </div></td>
              </tr>
              <tr>
                <td width="357" align="left" class="Estilo82">Cubrió sus expectativas?</td>
                <td width="70" align="right"><div align="center">
                  <input type="radio" name="CUBRIO SUS ESPECTATIVAS?" value="si"  onclick="habilita(this.form)" />
                </div></td>
                <td><div align="center">
                  <input type="radio" name="CUBRIO SUS ESPECTATIVAS?" value="no" onclick="deshabilita(this.form)" />
                </div></td>
              </tr>
              <tr>
                <td width="357" align="left" class="Estilo82">Indique su n° de habitación:</td>
                <td colspan="2" align="right"><div align="center">
                  <label for="HABITACION NUMERO"></label>
                  <input name="HABITACION NUMERO" type="text" id="HABITACION NUMERO" size="10" maxlength="10" />
                </div>                  <div align="center"></div></td>
                </tr>
              <tr>
                <td colspan="3" align="left">&nbsp;</td>
              </tr>
              <tr>
                <td colspan="3" align="left"><strong>2. Restaurante y Bar</strong></td>
              </tr>
              <tr>
                <td align="left" class="Estilo82"><strong>¿Fue usted atendido con:</strong></td>
                <td align="center"><strong>SI</strong></td>
                <td align="center"><strong>NO</strong></td>
              </tr>
              <tr>
                <td width="357" align="left" class="Estilo82">Amabilidad?</td>
                <td width="70" align="right"><div align="center">
                  <input type="radio" name="Restaurante y Bar: ATENCION AMABLE?" value="si" onclick="habilita(this.form)" />
                </div></td>
                <td><div align="center">
                  <input type="radio" name="Restaurante y Bar: ATENCION AMABLE?" value="no" onclick="deshabilita(this.form)" />
                </div></td>
              </tr>
              <tr>
                <td align="left" class="Estilo82">Eficacia?</td>
                <td align="right"><div align="center">
                  <input type="radio" name="Restaurante y Bar: ATENCION EFICAZ?" value="si" onclick="habilita(this.form)" />
                </div></td>
                <td><div align="center">
                  <input type="radio" name="Restaurante y Bar: ATENCION EFICAZ?" value="no" onclick="deshabilita(this.form)" />
                </div></td>
              </tr>
              <tr>
                <td width="357" align="left" class="Estilo82">Fue satisfactoria la calidad de nuestro productos?</td>
                <td width="70" align="right"><div align="center">
                  <input type="radio" name="Restaurante y Bar: CALIDAD?" value="si" onclick="habilita(this.form)" />
                </div></td>
                <td><div align="center">
                  <input type="radio" name="Restaurante y Bar: CALIDAD?" value="no" onclick="deshabilita(this.form)" />
                </div></td>
              </tr>
              <tr>
                <td align="left">&nbsp;</td>
                <td align="right">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="3" align="left"><strong>3. Servicios en general</strong></td>
                </tr>
              <tr>
                <td align="left"><span class="Estilo82"><strong>¿Fueron satisfactorios nuestros servicios de:</strong></span></td>
                <td align="center"><strong>SI</strong></td>
                <td align="center"><strong>NO</strong></td>
              </tr>
              <tr>
                <td align="left"><span class="Estilo82">Recepción?</span></td>
                <td align="center"><input type="radio" name="SATISFACCION con RECEPCION?" value="si" onclick="habilita(this.form)" /></td>
                <td align="center"><input type="radio" name="SATISFACCION con RECEPCION?" value="no" onclick="deshabilita(this.form)" /></td>
              </tr>
              <tr>
                <td align="left"><span class="Estilo82">Valet Parking?</span></td>
                <td align="center"><input type="radio" name="SATISFACCION con VALET PARKING?" value="si" onclick="habilita(this.form)" /></td>
                <td align="center"><input type="radio" name="SATISFACCION con VALET PARKING?" value="no" onclick="deshabilita(this.form)" /></td>
              </tr>
              <tr>
                <td align="left" class="Estilo82">Health Club?</td>
                <td align="center"><input type="radio" name="SATISFACCION con HEALTH CLUB?" value="si" onclick="habilita(this.form)" /></td>
                <td align="center"><input type="radio" name="SATISFACCION con HEALTH CLUB?" value="no" onclick="deshabilita(this.form)" /></td>
              </tr>
              <tr>
                <td align="left" class="Estilo82">Desayunos?</td>
                <td align="center"><input type="radio" name="SATISFACCION con DESAYUNOS?" value="si" onclick="habilita(this.form)" /></td>
                <td align="center"><input type="radio" name="SATISFACCION con DESAYUNOS?" value="no" onclick="deshabilita(this.form)" /></td>
              </tr>
              <tr>
                <td align="left" class="Estilo82">Limpieza?</td>
                <td align="center"><input type="radio" name="SATISFACCION con LIMPIEZA?" value="si" onclick="habilita(this.form)" /></td>
                <td align="center"><input type="radio" name="SATISFACCION con LIMPIEZA?" value="no" onclick="deshabilita(this.form)" /></td>
              </tr>
            </table>
            <hr color="#CCCCCC" size="1" width="96%" />
            <br />
            <table width="624" border="0" align="center">
              <tr>
                <td width="528"><span class="Estilo80">4. Apreciamos mucho sus observaciones especiales:</span></td>
              </tr>
            </table>
            <table width="620" border="0">
              <tr>
                <td colspan="3"><div align="left">
                  <textarea name="OBSERVACIONES ESPECIALES" cols="74" rows="8" id="OBSERVACIONES ESPECIALES"></textarea>
                </div></td>
              </tr>
              <tr>
                <td width="413" height="35" valign="bottom">&nbsp;</td>
                <td width="112" valign="bottom"><span style="text-align: justify">
                  <input type="reset" value="   BORRAR  " name="B2" />
                </span></td>
                <td width="81" valign="bottom"><span style="text-align: justify">
                  <input type="submit" value="   ENVIAR   " name="" />
                </span></td>
              </tr>
            </table>
            <img src="pie.jpg" width="1000" height="200" />
          </form>
        </div>
        <!-- END COL1-->
        <!-- END COL2-->
      </div>
      <!-- END CONTENT-->
    </div>
      <div align="center">
        <script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
              </script>
 
      </div></td>
  </tr>
</table>
 
</body>
</html>
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 SALVADOR

Como hago que los campos SEAN TODOS OBLIGATORIOS PARA CONTESTAR UNA ENCUESTA

Publicado por SALVADOR (125 intervenciones) el 10/07/2014 16:18:36
Debes utilizar Javascript para hacer esto, de lo contrario, primero envias el formulario y una vez que recibes, validas y le informas al usuario que los datos son requeridos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Como hago que los campos SEAN TODOS OBLIGATORIOS PARA CONTESTAR UNA ENCUESTA

Publicado por john arroyave (3 intervenciones) el 11/07/2014 14:19:46
Saludos.

Si es antes de enviarlo con JS, si es después con el PHP en la página que los recibe.

Si vas a crear aplicaciones PHP te recomiendo usar Practico http://www.practico.org un framework que en cuestión de minutos te permite crear aplicaciones complejas y hacer ese tipo de validaciones de manera automática.

Felíz día.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Como hago que los campos SEAN TODOS OBLIGATORIOS PARA CONTESTAR UNA ENCUESTA

Publicado por jexica (11 intervenciones) el 11/07/2014 14:41:55
Hola yo estoy trabajando un formulario con algunos campos obligatorios, pero con el modelo MVC y orientado a objetos a ver si te sirve esto.
Formulario de Login
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
<head>
<link rel="stylesheet" type="text/css" href="../css/style.css">
</head>
 
<body>
 
<table bgcolor="#FFFFCC" width="514" height="181" border="10px" align="center"  vspace="0" >
  <tr>
    <td colspan="2"  align="center"  style="text-align:center"  >
	<form action = "../controlador/validarclave.php" method = "post">
    <p class="Estilo2">
   Cedula: <input type= "text" name="cedula" size= "15" >
   Password: <input type ="password" name="pwd" size="15"> <br>  <br>
   <input type ="submit" name="Ingresar" value="Ingresar">
   </form>
    </td>
  </tr>
  <tr>
 
 
</table>
 
 
</body>
</html>

Aqui recibo mis datos para mantener la session

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
	session_start();
	require_once('usuario.php');
	require_once('../modelo/class_mysql.php');
	$cedula=$_POST['cedula'];
	$password=$_POST['pwd'];
	$_SESSION['cedula']=$_POST['cedula'];
    $_SESSION['password']=$_POST['pwd'];
 
 
 
	$usuario=new usuario();   //instanciamos la clase $nombreclase=new nombreclase();     
	$validarclave=$usuario->validarclave($cedula,$password); //$function=$clase->function(valores de inicio)
 
?>


Aqui defino mi clase y realizo la funcion de validacion tanto de introduccion de campos como de el usuario en la BD

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
<?php
 
require_once('../modelo/class_mysql.php');
 
class usuario {
 
 
	public function __construct () {
 
	$this->mysql = new mysql();
	}
//funcion para validar usuario y clave
 
	function validarclave($cedula,$password){
 
		if(isset($cedula) && !empty($cedula) &&  //verifico la introduccion de usuario y password si no hay datos esto me lleva al scrip que muestra el error y no permite hacer la consulta en la BD
	  isset($password) && !empty($password)) {
 
		$sql = "SELECT * FROM usuario WHERE id_cedula='".$cedula."';";
 
		  if( $cedula!="" or $password!=""){
 
			$conexion =$this->mysql->conectar();
			$resultado= $this->mysql->bd_nrows($sql,$conexion);
			$this->mysql->desconectar($conexion);
 
 
				if ($resultado==0){
 
			//el usuario no existe 
				echo "<script type='text/javascript'>
							alert('Usuario o clave incorrecto');
						window.location='../vista/login.php';
						</script>";
	    		}
				else{
				$sql= "SELECT * FROM usuario WHERE id_cedula='".$cedula."' AND password='".$password."';";
				$conexion =$this->mysql->conectar();
				$resultado= $this->mysql->bd_mfa($sql,$conexion);
				$this->mysql->desconectar($conexion);
 
					if($resultado==0){
 
				// Clave incorrecta 
					echo "<script type='text/javascript'>
							alert('Usuario o clave incorrecto');
							window.location='../vista/login.php';
							</script>";
 
					}
 
						else{ // existe y vamos a menu de seleccion 
				header ("Location:../vista/vista_menu.php");
						}
 
				}
 
		  }
 
	else{
	$this->mysql->desconectar($conexion);
	header ("Location:../vista/menu.php");
 
}
 
 } else { // no Introdujo los campos obligatorios 
 
echo  "<script type='text/javascript'>
							alert('Error, no ha introducido todos los datos');
						window.location='../vista/login.php';
						</script>";
 
}
 
}


Espero que te ayude.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar