Ayuda formularios!
Publicado por Emiliano (1 intervención) el 28/06/2009 21:23:35
tengo el siguiente problema.. necesito enviar un formulario de contacto y validar que los campos sean correctos.. hasta ahí mi solución funciona, pero quiero que si algún dato es erróneo no me borre todos los campos para comenzar de 0 a completarlo sino que vuelva con los datos que ya había ingresado anteriormente...
les voy a agradecer enormemente la ayuda!!!
les pego el código:
Contacto.php:
<form id="contacto" height = "300" width="600" align="center">
<br>
<p align="center"> <h4 align="center">Por favor complete los campos: </h4></p>
<font color="858585"><b>
<div id="celdas"><div> Apellido y Nombre:
<br><br>
E-mail:
<br><br>
Asunto:
<br><br>
Nos conocio por:
</b><p><p>
</div>
<div> <input type="text" name="nombre" id="nombre" size="25">
<br><br>
<input type="text" name="email" id="email" size="25">
<br><br>
<input type="text" name="asunto" id="asunto" size="25">
<br><br>
Internet<input type="checkbox" name="web" style="CURSOR: url('hand.cur'), auto">
Periódico<input type="checkbox" name="periodico" style="CURSOR: url('hand.cur'), auto">
Otros<input type="checkbox" name="otros" style="CURSOR: url('hand.cur'), auto">
<br><br>
</div>
<div> <img src="./imagenes/manos.png" border="0" >
</div>
</div>
<br class="clearfloat">
<div> <div id="celdas2"><div><b>Mensaje:</b>
</div>
<div> <textarea cols= '35' rows= '7' name="mensaje" id="mensaje"></textarea>
<p><p>
</div>
</div>
</font>
<br class="clearfloat">
<div align="right"> <input type="reset" name="limpiar" value="Limpiar" style="CURSOR: url('hand.cur'), auto">
<input type="Submit" name="enviar" value="Enviar" onClick="comprobar();" style="CURSOR: url('hand.cur'), auto">
</div>
</form>
y la función comprobar completa sería:
Código:
function validaremail(txt){
var b = /^[^@s]+@[^@.s]+(.[^@.s]+)+$/
if (!b.test(txt)) {
alert('Email no vxe1lido.');
}
return b.test(txt)
}
function comprobar() {
if ((document.getElementById('nombre').value == '') || (document.getElementById('email').value == '')
|| (document.getElementById('asunto').value == '') || (document.getElementById('mensaje').value == ''))
{
alert('Debe Completar todos los datos requeridos.');
}
else
{
validaremail(document.getElementById('email').value)
}
}
espero su ayuda
les voy a agradecer enormemente la ayuda!!!
les pego el código:
Contacto.php:
<form id="contacto" height = "300" width="600" align="center">
<br>
<p align="center"> <h4 align="center">Por favor complete los campos: </h4></p>
<font color="858585"><b>
<div id="celdas"><div> Apellido y Nombre:
<br><br>
E-mail:
<br><br>
Asunto:
<br><br>
Nos conocio por:
</b><p><p>
</div>
<div> <input type="text" name="nombre" id="nombre" size="25">
<br><br>
<input type="text" name="email" id="email" size="25">
<br><br>
<input type="text" name="asunto" id="asunto" size="25">
<br><br>
Internet<input type="checkbox" name="web" style="CURSOR: url('hand.cur'), auto">
Periódico<input type="checkbox" name="periodico" style="CURSOR: url('hand.cur'), auto">
Otros<input type="checkbox" name="otros" style="CURSOR: url('hand.cur'), auto">
<br><br>
</div>
<div> <img src="./imagenes/manos.png" border="0" >
</div>
</div>
<br class="clearfloat">
<div> <div id="celdas2"><div><b>Mensaje:</b>
</div>
<div> <textarea cols= '35' rows= '7' name="mensaje" id="mensaje"></textarea>
<p><p>
</div>
</div>
</font>
<br class="clearfloat">
<div align="right"> <input type="reset" name="limpiar" value="Limpiar" style="CURSOR: url('hand.cur'), auto">
<input type="Submit" name="enviar" value="Enviar" onClick="comprobar();" style="CURSOR: url('hand.cur'), auto">
</div>
</form>
y la función comprobar completa sería:
Código:
function validaremail(txt){
var b = /^[^@s]+@[^@.s]+(.[^@.s]+)+$/
if (!b.test(txt)) {
alert('Email no vxe1lido.');
}
return b.test(txt)
}
function comprobar() {
if ((document.getElementById('nombre').value == '') || (document.getElementById('email').value == '')
|| (document.getElementById('asunto').value == '') || (document.getElementById('mensaje').value == ''))
{
alert('Debe Completar todos los datos requeridos.');
}
else
{
validaremail(document.getElementById('email').value)
}
}
espero su ayuda
Valora esta pregunta


0