
No me toma la validacion
Publicado por Facundo (6 intervenciones) el 03/05/2014 17:06:20
Buenas. Tengo una duda, quiero saber porque no me toma la validacion jquery-validation.
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Punto 3</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#formPHP").validate({
rules: {
'txtProducto': 'required',
'txtCantidad': {required: true , number: true}
},
messages: {
'txtProducto': 'Producto requerido ',
'txtCantidad': 'Cantidad invalido '
},
});
});
</script>
</head>
<body>
<?php
session_start();
?>
<table>
<form method="GET" id="formPHP" name="formPHP">
<tr>
<th>Producto</th>
<td><input type="text" name="txtProducto" id="txtProducto"/></td>
</tr>
<tr>
<th>Cantidad</th>
<td><input type="text" name="txtCantidad" id="txtCantidad"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Añadir al Carrito" name="btnEnviar" id="btnEnviar"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Eliminar Sesion" name="btnEliminar" id="btnEliminar"/></td>
</tr>
</form>
</table>
<?php
if(isset($_REQUEST["btnEnviar"])){
$producto = $_REQUEST["txtProducto"];
$cantidad = $_REQUEST["txtCantidad"];
$_SESSION['Contador'][] = $producto;
if(count($_SESSION['Contador']) == 1){
$_SESSION['Producto'][] = $producto;
$_SESSION['Cantidad'][] = $cantidad;
}else{
if(in_array($producto,$_SESSION['Producto'])){
for($i=0; $i < count($_SESSION['Producto']); $i++){
if($_SESSION['Producto'][$i] == $producto){
$_SESSION['Cantidad'][$i] = $_SESSION['Cantidad'][$i] + $cantidad;
break;
}
}
}else{
$_SESSION['Producto'][] = $producto;
$_SESSION['Cantidad'][] = $cantidad;
}
}
for($i=0; $i < count($_SESSION['Producto']); $i++){
echo 'Producto: '.$_SESSION['Producto'][$i].' Cantidad: '.$_SESSION['Cantidad'][$i].'</br>';
}
}
if(isset($_REQUEST['btnEliminar'])){
session_destroy();
}
?>
</body>
</html>
Valora esta pregunta


0