Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

vinih

[Resolvido] Form, Campos vazios.

Recommended Posts

Olá galera,

 

Eu fiz um sistema de contato, a pessoa digita o nome, email, e a mensagem e talz; e é salvo no bd tudo certinho.

 

Só que,

 

A pessoa pode dexar tudo em branco e enviar do mesmo jeito, queria que fosse mandado uma aviso pra ela +/- assim: o campo nome está em branco, e voltasse para a pagina de contato.

 

Ja pesquisei varios codigos; mais em html num tá funcionando num sei porque;

 

Vo mandar o codigo todo com layout e tudo.

 

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<!-- This Site Was Designed By Wayne D. Fields ( http://illusivedesign.org - http://supremetemplates.com ) -->

<html>

<head>

 

<meta NAME="description" CONTENT="Your site description here.">

<meta NAME="keywords" CONTENT="Your site keywords here.">

<meta name="revisit-after" content="4days">

<meta name="robots" content="index,follow">

 

<title>X-TudoBR</title>

 

<script language="JavaScript">

<!--

function MM_reloadPage(init) { //reloads the window if Nav4 resized

if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}

else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

MM_reloadPage(true);

// -->

</script>

 

<link rel="stylesheet" href="style1.css" type="text/css" media="screen">

<script type="text/javascript" src="mover.js"></script>

</head>

 

<body bgcolor="#000000" marginwidth="5" marginheight="5" leftmargin="5" topmargin="5">

 

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>

<td align="center" valign="top">

<table width="730" border="0" cellpadding="0" cellspacing="0"><tr>

<td valign="top">

<table border="0" cellpadding="0" cellspacing="0">

<tr>

<td><img src="images/temp3_01.gif" width="426" height="64"></td>

<td><img src="images/temp3_02.gif" width="112" height="64"></td>

<td><img src="images/temp3_03.gif" width="177" height="64"></td>

<td><img src="images/temp3_04.gif" width="15" height="64"></td>

</tr>

 

<tr>

<td rowspan="5"><img src="images/temp3_05.gif" width="426" height="103"></td>

<td rowspan="5"><img src="images/temp3_06.gif" width="112" height="103"></td>

<td><a href="index.html" onmouseover="on1();" onmouseout="off1();"><img src="images/butt_home.gif" width="177" height="20" border="0" name="a"></a></td>

<td rowspan="5"><img src="images/temp3_08.gif" width="15" height="103"></td>

</tr>

 

<tr>

<td><a href="company.html" onmouseover="on2();" onmouseout="off2();"><img src="images/butt_company.gif" width="177" height="20" border="0" name="b"></a></td>

</tr>

 

<tr>

<td><a href="products.html" onmouseover="on3();" onmouseout="off3();"><img src="images/butt_products.gif" width="177" height="20" border="0" name="c"></a></td>

</tr>

 

<tr>

<td><a href="services.html" onmouseover="on4();" onmouseout="off4();"><img src="images/butt_services.gif" width="177" height="20" border="0" name="d"></a></td>

</tr>

 

<tr>

<td><a href="contato.htm" onmouseover="on5();" onmouseout="off5();"><img src="images/butt_contact.gif" width="177" height="23" border="0" name="e"></a></td>

</tr>

</table>

</td>

</tr><tr>

<td valign="top">

<table border="0" cellpadding="0" cellspacing="0">

<tr>

<td><img src="images/temp3_13.gif" width="210" height="29"></td>

<td><img src="images/temp3_14.gif" width="283" height="29"></td>

<td><img src="images/temp3_15.gif" width="237" height="29"></td>

</tr>

 

<tr>

<td><img src="images/temp3_16.gif" width="210" height="20"></td>

<td><img src="images/spacer.gif" width="283" height="20"></td>

<td><img src="images/temp3_18.gif" width="237" height="20"></td>

</tr>

 

<tr>

<td><img src="images/temp3_19.gif" width="210" height="17"></td>

<td width="283" height="17" class="title"><!-- Page Title --> Bem vindo ao

X-TudoBR <!-- Page Title --></td>

<td><img src="images/temp3_21.gif" width="237" height="17"></td>

</tr>

</table>

</td>

</tr><tr>

<td valign="top">

<table border="0" cellpadding="0" cellspacing="0"><tr>

<td width="194" height="310" valign="top">

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>

<td background="images/bg_sidepanel.gif" align="center" valign="top">

<table border="0" cellpadding="0" cellspacing="0"><tr>

<td colspan="2" background="images/bg_pan_title.gif" width="194" height="20" class="pan_title">

<img src="images/spacer.gif" width="20" height="5"><!-- TITLE -->Area VIP<!-- TITLE --></td>

</tr><tr><td><img src="images/spacer.gif" width="15" height="5"></td>

<td class="pan">Login:<br>

<input name="text" type="text" style="height:20px; width:150px;"></td>

</tr><tr><td><img src="images/spacer.gif" width="15" height="5"></td>

<td class="pan">Senha:<br>

<input name="text" type="text" style="height:20px; width:150px;"></td>

</tr><tr><td><img src="images/spacer.gif" width="15" height="5"></td>

<td><input type="image" src="images/butt_login.jpg"></td></tr></table><br>

 

<table border="0" cellpadding="0" cellspacing="0"><tr>

<td colspan="2" background="images/bg_pan_title.gif" width="194" height="20" class="pan_title">

<img src="images/spacer.gif" width="20" height="5"><!-- TITLE -->News X-TudoBR<!-- TITLE --></td>

</tr><tr><td><img src="images/spacer.gif" width="10" height="5"></td>

<td class="pan"><p><a href="http://supremetemplates.com" target="_blank">

</a>X-TudoBR Fundado, vamos divulgar gente.<br>

<a href="http://supremetemplates.com" target="_blank"></a><br>

<a href="http://supremetemplates.com" target="_blank"></a><br>

<a href="#"><img src="images/butt_more.jpg"width="81" height="16" border="0"></a></p>

</td></tr></table><br>

 

</td></tr><tr>

<td valign="top" height="38">

<img src="images/pan_bottom.gif" width="194" height="38" border="0">

</td></tr></table>

</td>

<td width="536" height="310" valign="top">

<table width="536" border="0" cellpadding="0" cellspacing="0"><tr>

<td><img src="images/con_area_01.gif" width="20" height="20"></td>

<td><img src="images/con_area_02.gif" width="500" height="20"></td>

<td><a href="#" onMouseover="moveup()" onMouseout="clearTimeout(moveupvar)">

<img src="images/butt_up.gif" width="16" height="20" border="0"></a></td>

</tr><tr>

<td><img src="images/con_area_04.gif" width="20" height="250"></td>

<td width="500" height="250" valign="top">

 

<script language="JavaScript1.2">

iens6=document.all||document.getElementById

ns4=document.layers

 

//specify speed of scroll (greater=faster)

var speed=5

 

if (iens6){

document.write('<div id="container" style="position:relative;width:495;height:245;border:0px solid white;overflow:hidden">')

document.write('<div id="content" style="position:absolute;width:495;left:0;top:0">')

}

</script>

 

<ilayer name="nscontainer" width=490 height=240 clip="0,0,175,160">

<p>

<center>

<p>

</center>

<layer name="nscontent" width=490 height=240 visibility=hidden>

<!--INSERT CONTENT HERE-->

<p><strong></strong>

<p> 

<center>

<font size="2" color="#ffffff"><strong>

<form method="POST" action="Contato\enviar.php">

<p>

Nome:<input type="text" name="nome" size="20"></p>

<p>Email: <input type="text" name="email" size="20"></p>

<p>Mensagem:

<textarea name="mensagem" cols="20"></textarea>

</p>

<p><input type="submit" value="Submeter" name="B1"><input type="reset" value="Redefinir" name="B2"></p>

</form>

</strong></font>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="business" value="deonya24@yahoo.com">

<input type="hidden" name="item_name" value="Supreme Template Licence">

<input type="hidden" name="item_number" value="Supreme Temp3">

<input type="hidden" name="amount" value="20.00">

<input type="hidden" name="return" value="http://www.supremetemplates.com">

<input type="hidden" name="cancel_return" value="http://www.supremetemplates.com">

<input type="hidden" name="currency_code" value="USD">

</form>

<p> 

<p><a href="http://supremetemplates.com" target="_blank"

onMouseOver="window.status='Visit Supreme Templates we have the largest selection of templates on the net.'; return true;"

onMouseOut="window.status=''; return true;"> </a>

</center>

<!--END CONTENT-->

</layer>

</ilayer>

<script language="JavaScript1.2">

if (iens6)

document.write('</div></div>')

</script>

 

<script language="JavaScript1.2">

if (iens6){

var crossobj=document.getElementById? document.getElementById("content") : document.all.content

var contentheight=crossobj.offsetHeight

}

else if (ns4){

var crossobj=document.nscontainer.document.nscontent

var contentheight=crossobj.clip.height

}

 

function movedown(){

if (iens6&&parseInt(crossobj.style.top)>=(contentheight*(-1)+100))

crossobj.style.top=parseInt(crossobj.style.top)-speed

else if (ns4&&crossobj.top>=(contentheight*(-1)+100))

crossobj.top-=speed

movedownvar=setTimeout("movedown()",20)

}

 

function moveup(){

if (iens6&&parseInt(crossobj.style.top)<=0)

crossobj.style.top=parseInt(crossobj.style.top)+speed

else if (ns4&&crossobj.top<=0)

crossobj.top+=speed

moveupvar=setTimeout("moveup()",20)

 

}

 

function getcontent_height(){

if (iens6)

contentheight=crossobj.offsetHeight

else if (ns4)

document.nscontainer.document.nscontent.visibility="show"

}

window.onload=getcontent_height

</script>

 

</td>

<td><img src="images/con_area_06.gif" width="16" height="250"></td>

</tr><tr>

<td><img src="images/con_area_07.gif" width="20" height="8"></td>

<td><img src="images/con_area_08.gif" width="500" height="8"></td>

<td><img src="images/con_area_09.gif" width="16" height="8"></td>

</tr><tr>

<td><img src="images/con_area_10.gif" width="20" height="20"></td>

<td width="500" height="20" align="center">

<!-- Bottom Menu -->

<a href="index.html">Home</a> |

<a href="company.html">X-TudoBR</a> |

<a href="products.html">Vip</a> |

<a href="services.html">Serviços</a> |

<a href="contato.htm">Contato</a>

<!-- Bottom Menu -->

</td>

<td><a href="#" onMouseover="movedown()" onMouseout="clearTimeout(movedownvar)">

<img src="images/butt_down.gif" width="16" height="20" border="0"></a></td>

</tr><tr>

<td colspan="2"><img src="images/con_area_13.gif" width="520" height="12"></td>

<td><img src="images/con_area_14.gif" width="16" height="12"></td>

</tr></table>

 

</td>

</tr>

</table>

</td>

</tr><tr>

<td valign="top">

<table border="0" cellpadding="0" cellspacing="0">

<tr>

<td><img src="images/temp3_24.gif" width="210" height="43"></td>

<td><img src="images/temp3_25.gif" width="216" height="43"></td>

<td><img src="images/temp3_26.gif" width="304" height="43"></td>

</tr></table>

</td></tr></table>

</td></tr></table>

<center>

<!-- Copyright -->

<font size="1">

© Copyright 2008 X-TudoBR<br>

All Rights Reserved.</font>

<!-- Copyright --></center>

</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

no FORM:

<FORM ... ... onSubmit="return Valida()">
no HEADER você faz uma função em JS:

<script>
function Valida(){
if(document.form.nome.vale="" && document.form.email.value="" && document.form.comentarios.value="")
   {
	   if(confirm('Todos os campos estão em branco. Deseja enviar assim mesmo?'))return true; else return false;
   }
}

Arruma os nomes do form e dos campos.

Se clicar em OK, envia. Se clicar em Cancel, não faz nada.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Naum funcionou,

E eu quero que retorne direto sem perguntar,

 

Olha como eu deixei será que está errado ?

 

<form method="POST" action="Contato\enviar.php" onSubmit="return Valida()">
<p>
  Nome:<input type="text" name="nome" size="20"></p>
  <p>Email: <input type="text" name="email" size="20"></p>
  <p>Mensagem:
	<textarea name="mensagem" cols="20"></textarea>
  <script>
function Valida(){
if(document.form.nome.value="" && document.form.email.value="" && document.form.mensagem.value="")
   {
	   if(confirm('Todos os campos estão em branco. Deseja enviar assim mesmo?'))return true; else return false;
   }
}
</p>
<p><input type="submit" value="Submeter" name="B1"><input type="reset" value="Redefinir" name="B2"></p>
</form>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Mudanças no código:

O ideal é você jogar a função Valida() dentro do cabeçalho da página, entre o <head> e </head>.

Depois, faltou o </script> após a chave final (eu esqueci quando postei :-)).

e por último, coloca um name="form" dentro da tag <form ...

 

Ai o código fica certo.

 

Mas ele vai perguntar se quer enviar ou não. Se quiser que não envie até um dos compos ser preenchido, segue o nova função Valida():

 

<script>
function Valida()
{
   if(document.form.nome.value="" && document.form.email.value="" && document.form.mensagem.value="")
   {
	   alert('Nenhum campo foi preenchido.');
	   return false;
   }
   else
	   return true;
}
</script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olha como eu fiz, funcionou mais eu quero validar 3 campos não só 1;

desse jeito que você falo naum funcionou;

como fica o codigo pra validar 3 campos ?

 

 

<script language="Javascript">
function valida()
{
<!--
var nome = document.contato.nome.value
if (nome==""){
	alert("É necessário o preenchimento de todos os campos");
	document.contato.nome.focus()
	return false
	}
}
//-->
</script>
<form action="Contato/enviar.php" name="contato" method="post" onsubmit="return valida()">
<p>Nome:
	<input type="text" name="nome" size="15">
</p>
<p>  Email:
	<input type="text" name="email" size="15">
  </p>
<p>Mensagem:</p>
<p>	<textarea name="mensagem" cols="15"></textarea>
</p>
<p>	<input type="submit" value="Enviar">
  
	<input type="reset" value="Redefinir">

Compartilhar este post


Link para o post
Compartilhar em outros sites

Experimenta Mudar para isso:

 

<script>
function Valida()
{
   if(document.form.nome.value="" && document.form.email.value="" && document.form.mensagem.value="")
   {
	   alert('Nenhum campo foi preenchido.');
	   return false;
   }
   else
	   return true;
}
</script>

<form action="Contato/enviar.php" name="contato" method="post" onsubmit="return valida()">
<p>Nome:
	<input type="text" name="nome" size="15">
</p>
<p>  Email:
	<input type="text" name="email" size="15">
  </p>
<p>Mensagem:</p>
<p>	<textarea name="mensagem" cols="15"></textarea>
</p>
<p>	<input type="submit" value="Enviar">
  
	<input type="reset" value="Redefinir">

Compartilhar este post


Link para o post
Compartilhar em outros sites

Seu código ta errado amigo, fiz umas correções, segue:

 

<script language="JavaScript" type="text/javascript">
<!--
function Valida()
{
   if(document.contato.nome.value=="" || document.contato.email.value=="" || document.contato.mensagem.value=="")
   {
	   alert('Nenhum campo foi preenchido.');
	   return false;
   }
   else
	   return true;
}
-->
</script>
<form action="Contato/enviar.php" name="contato" method="post" onsubmit="return Valida(this);">
<p>Nome:
	<input type="text" name="nome" size="15">
</p>
<p>  Email:
	<input type="text" name="email" size="15">
  </p>
<p>Mensagem:</p>
<p>	<textarea name="mensagem" cols="15"></textarea>
</p>
<p>	<input type="submit" value="Enviar">
  
	<input type="reset" value="Redefinir">

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.