Quantcast
Channel: Fórum ASP
Viewing all articles
Browse latest Browse all 1214

Formulario não critica campo não preenchido

$
0
0

O formulário insere os registros na tabela mas não critica os campos.

O código do formulário é esse:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!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>
<title>Inserir livros na tabelas de livros</title>
<!-- Esse código funciona-->
<script language="javascript">
function validaForm() {
if (document.formLivro.txtCodigo.value.length <1)
{alert("O campo ISBN não pode ficar em branco. ");
formLivro.txtCodigo.focus();
return false;
}
if (document.formLivro.txtCodCategoria.value.length <1)
{alert("O campo Código da Categoria não pode ficar em branco.")
formLivro.txtCodCategoria.focus();
return false;
}
if (document.formLivro.txtTitulo.value.length <1)>
{alert("O campo Título não pode ficar em branco.");
formLivro.txtTitulo.focus();
return false;
}
if (documento.formLivro.txtAutor.value.length <1)
{alert("Ocampo Autor não pode ficar em branco.");
formLivro.txtAutor.focus();
return false;
}
if (document.formLivro.txtPreco.value.length <1)
{alert("O campo Preço não pode ficar em branco.")
formLivro.txtPreco.focus();
return false;
}
if (document.formLivro.txtCapa.value.length <1)
{alert("O campo Imagem da Capa não pode ficar em branco.")
formLivro.txtCapa.focus();
return false
}
return true;
}
</script> 
</head>
<body>
<form name="formLivro" method="post"  action="ResLab10_1.asp" onsubmit="return validaForm(this);">
Inclusão de Livros<br /><br />
Informe os dados do livro a ser inserido. Os campos com (*) são de digitação obrigatória.<br />

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20%">ISBN: </td>
<td width="80%"> <input name="txtCodigo"  type="text" />
 *</td>
</tr>

<tr>
<td width="20%">Código da Categoria:</td>
<td width="80%"> <input type="text" name="txtCodCategoria" /> *</td>
</tr>

<tr>
<td width="20%">Título:</td>
<td width="80%"> <input type="text" name="txtTitulo" /> *</td>
</tr>

<tr>
<td width="20%">Autor:</td>
<td width="80%"> <input type="text" name="txtAutor"  /> *</td>
</tr>

<tr>
<td width="20%">Número de páginas:</td>
<td width="80%"> <input type="text" name="txtNPaginas" /></td>
</tr>

<tr>
<td width="20%">Formato:</td>
<td width="80%"> <input type="text" name="txtFormato" /></td>
</tr>

<tr>
<td width="20%">Preço:</td>
<td width="80%"> <input type="text" name="txtPreco" /> *</td>
</tr>

<tr>
<td width="20%">Resenha:</td>
<td width="80%"> <textarea name="txtResenha" rows="5" cols="40"></textarea></td>
</tr>

<tr>
<td width="20%">Lançamento (S/N): </td>
<td width="80%"> <input type="text" name="txtLancamento" /></td>
</tr>

<tr>
<td width="20%">Data Publicação: </td>
<td width="80%"> <input type="text" name="txtDataPub" /></td>
</tr>

<td width="20%"></td>
<td width="80%">
<input type="submit" value="Inserir" name="btInsere" />
<input type="reset" value="Limpa campos" name="btLimpa" />
</td>
</tr>
</table>
</form>
</body>
</html>

O a página é essa:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Option Explicit 
%>

<!--#Include file="dbConexao.asp"-->

<%
Dim conexaoDataBase
Dim strIns, rsLivros
Dim varCodigo, varCodCategoria, varTitulo, varAutor, varNPaginas, varFormato, varPreco, varResenha, varLancamento, varDataPub 
VarCodigo = TRIM(Request.Form("txtCodigo"))
VarCodCategoria = Request.Form("txtCodCategoria")
VarTitulo = TRIM(Request.Form("txtTitulo"))
varAutor = TRIM(Request.Form("txtAutor"))
VarNPaginas = Request.Form("txtNPaginas")
VarFormato = TRIM(Request.Form("txtFormato"))
VarPreco = Request.Form("txtPreco")
VarResenha = Request.Form("txtResenha")
VarLancamento = TRIM(Request.Form("txtLancamento"))
VarDataPub = TRIM(Request.Form("txtDataPub"))
varTitulo = REPLACE(varTitulo, "'", " ")
varAutor = REPLACE(varAutor, "'", " ")
VarFormato = REPLACE(VarFormato, "'", " ")
VarResenha = REPLACE(VarResenha, "'", " ")
VarPreco = REPLACE(VarPreco, ",", ".")
strINS = "INSERT into Livros "
strINS = strINS & "(codLivro, Categoria, titulo, autor, npaginas, formato, preco, resenha, lancamento, dataPub)"
strINS = strINS + "VALUES ('" + varCodigo + "', "
strINS = strINS + "'" + varCodCategoria + "', "
strINS = strINS + "'" + varTitulo + "', "
strINS = strINS + "'" + varAutor + "', "
strINS = strINS + varNPaginas + ","
strINS = strINS + "'" + varFormato + "', "
strINS = strINS + varPreco + ", "
strINS = strINS + "'" + varResenha + "', "
strINS = strINS + "'" + varLancamento + "', "
strINS = strINS + "'" + varDataPub + "')"

Call abreConexao
Set rsLivros = conexaoDataBase.Execute(strINS)
%>

<!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>Inserindo dados em uma tabela</title>
</head>

<body>
O Livro: "<strong><% = varTitulo %></strong>" foi cadastrado com sucesso 
</body>
</html>
<%
Call fechaConexao
Set rsLivros = Nothing
%>

Não preenchendo um dos campos com * deveria informar por exemplo: "O campo Título não pode ficar em branco. Mas isso não ocorre. Deixando em branco informa erro:

 

 

Microsoft Office Access Database Engine erro '80004005'

O campo 'Livros.Titulo' não pode ser uma seqüência de caracteres de comprimento nulo.

/serieweb/nasp/laboratorios/ResLab10_1.asp, linha 41

 

a linha 41 é:

 

 

Set rsLivros = conexaoDataBase.Execute(strINS)

 

 


Viewing all articles
Browse latest Browse all 1214