Ver Mensaje Individual
  #6 (permalink)  
Antiguo 05/09/2011, 13:55
Avatar de ramongonzalez3000
ramongonzalez3000
 
Fecha de Ingreso: julio-2011
Mensajes: 3
Antigüedad: 13 años, 8 meses
Puntos: 0
Información Respuesta: Editar MM_validateForm

Hola Amigos,

Tengo el siguiente formulario con valores predeterminados con una función de javascript, para evitar gente malintencionada, he buscado la manera de que no se procesen esos valores predeterminados tratando de editar el código java pero no he tenido suerte. Igual he buscado en foros y he encontrado soluciones aplicables a restricciones de palabras que vienen de arreglos..., bueno la verdad es que no entiendo los códigos y quisiera saber si algunos de ustedes puede complementar este formulario para que procese valores distintos a los predeterminados.

// FORMULARIO

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25497914-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
</script>

</head>

<body>
<div id="logo">
<div align="center"><img src="atomo.jpg" width="212" height="343" alt="Logo" /></div>
</div>

<form name="atomo" action="insertar_datos.php" method="post" onsubmit="MM_validateForm('nombre','','R','apellid o','','R','empresa','','R','email','','NisEmail',' Mensaje','','R');return document.MM_returnValue" align="center">


<p align="center">
<input name="nombre" type="text" class="formu" id="nombre" value="Nombre" onfocus="if(this.value=='Nombre')this.value='';"
onblur="if(this.value=='')this.value='Nombre';">




<input name="apellido" type="text" class="formu" id="apellido" value="Apellido" onfocus="if(this.value=='Apellido')this.value='';"
onblur="if(this.value=='')this.value='Apellido';">




<input name="empresa" type="text" class="formu" id="empresa" value="Empresa" onfocus="if(this.value=='Empresa')this.value='';"
onblur="if(this.value=='')this.value='Empresa';">




<input name="email" type="text" class="formu" id="email"

value="email" onfocus="if(this.value=='email')this.value='';"
onblur="if(this.value=='')this.value='email';">

</p>
<p align="center">
<textarea name="Mensaje" id="Mensaje" cols="45" rows="5" class="formu" onfocus="if(this.value=='Mensaje')this.value='';"
onblur="if(this.value=='')this.value='Mensaje';">M ensaje</textarea>





</p>

<div align="center">
<input type="submit" value="Enviar">
</div>
</p>
</form>




</body>
</html>



// CODIGO PHP

<?php

if(isset($_POST['nombre'])&&!empty($_POST['nombre']) && isset($_POST['apellido'])&&!empty($_POST['apellido'])&&isset($_POST['empresa'])&&!empty($_POST['empresa'])&&isset($_POST['email'])&&!empty($_POST['email']))
{$link = mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("xxxx",$link);
mysql_query("INSERT INTO xxxx(nombre,apellido,empresa,email)VALUES('{$_POST['nombre']}','{$_POST['apellido']}','{$_POST['empresa']}','{$_POST['email']}')",$link);
$my_error = mysql_error($link);
if(!empty($my_error)) { echo "Ha habido un error al insertar los valores. $my_error"; }
else {print "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://www.atomo.com.ve/gracias.php'>";}
} else {
echo "Error, no ha introducido todos los datos";
}
?>