Ir para conteúdo

POWERED BY:

Arquivado

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

Paulo Mardson

Como saber se um campo do tipo $_FILE[ existe

Recommended Posts

Ae galera, eu fiz uma altenticação de formulario, mas ele só funciona se o campo(INPUT, TEXTAREA, FILE) existirem como faço essa condição??

tipo se o campo existir faça isso??

Compartilhar este post


Link para o post
Compartilhar em outros sites

Esse é o cód, e ele ta passando direto no firefox, não funciona =/

if (d.resumo.value != "") { 
					
					arquivo = (d.resumo.value);
					arquivo2 = (d.resumo2.value);
					arquivo3 = (d.resumo3.value);
					arquivo4 = (d.resumo4.value);
					
					tipo = arquivo.substring(arquivo.length-4,arquivo.length);
					tipo2 = arquivo2.substring(arquivo2.length-4,arquivo2.length);
					tipo3 = arquivo3.substring(arquivo3.length-4,arquivo3.length);
					tipo4 = arquivo4.substring(arquivo4.length-4,arquivo4.length);
					
					tipo = tipo.toLowerCase()
					tipo2 = tipo2.toLowerCase()
					tipo3 = tipo3.toLowerCase()
					tipo4 = tipo4.toLowerCase()

					if ((tipo == ".PDF") || (tipo == ".Pdf") || (tipo == ".pdf")) {} else {
						alert("RESUMO 1 - Formato inválido, Somente PDF.");
						d.resumo.focus();
					return false;
					}
					
				if(d.resumo2.value == "" || d.resumo3.value == "" || d.resumo4.value == ""){} else{
					
					if ((tipo2 == ".PDF") || (tipo2 == ".Pdf") || (tipo2 == ".pdf")) {} else {
						alert("RESUMO 2 - Formato inválido, Somente PDF.");
						d.resumo2.focus();
					return false;
					}
					
					if ((tipo3 == ".PDF") || (tipo3 == ".Pdf") || (tipo3 == ".pdf")) {} else {
						alert("RESUMO 3 - Formato inválido, Somente PDF.");
						d.resumo3.focus();
					return false;
					}
					if ((tipo4 == ".PDF") || (tipo4 == ".Pdf") || (tipo4 == ".pdf")) {} else {
						alert("RESUMO 4 - Formato inválido, Somente PDF.");
						d.resumo4.focus();
					return false;
					}
					}
					}
return true:
}

Esta é a página:

<?
	session_start();
	include ("../bloqueio.php");
	session_checker();
	
	include("../../admin/funcoes.php");
	conecta();

	$sql = "SELECT * FROM sisconecte WHERE id = '". $_SESSION["id"] ."'";
	$res = mysql_query($sql);
	$registros = mysql_num_rows($res);
	$linha = mysql_fetch_array($res);



if($linha[resumo] != ""){
	
	$input = '1.<input name="resumo" type="file" />';
	$botao = '<input value="Reenviar" type="submit" />';

}
if($linha[resumo2] != ""){
	
	$input2 = '2.<input name="resumo2" type="file" />';

}
if($linha[resumo3] != ""){
	
	$input3 = '3.<input name="resumo3" type="file" />';

}
if($linha[resumo4] != ""){
	
	$input4 = '4.<input name="resumo4" type="file" />';

}
?>	
<!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>Sis.Congresso - Reenvio de Arquivos</title>
<script type="text/javascript" src="../scripts/Validator.js"></script>
<style>
body{
	margin: 0 auto;
	padding: 0;
}
.style1 {
	font-family: "Trebuchet MS";
	font-weight: bold;
	color: #FFFFFF;
}
</style>
</head>

<body>
<form name="reenvio" action="reenviar.php" method="post" enctype="multipart/form-data" onsubmit="return validaReenvio()">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
	<td height="30" background="../img/bg_body.jpg" scope="col"><span class="style1">Reenvio de Arquivos</span></td>
  </tr>
  <tr>
	<td> </td>
  </tr>
  <tr>
	<td><div align="center"><? echo $input; ?></div></td>
  </tr>
  <tr>
	<td><div align="center"><? echo $input2; ?></div></td>
  </tr>
  <tr>
	<td><div align="center"><? echo $input3; ?></div></td>
  </tr>
	<tr>
	<td><div align="center"><? echo $input4; ?></div></td>
  </tr>
  <tr>
	<td> </td>
  </tr>
  <tr>
	<td height="30"><div align="center"><? echo $botao; ?></div></td>
  </tr>
</table>
</form>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Esse código JavaScript de validação está dentro da função "validaReenvio()"?

 

Pois pelo que entendi o código JavaScript está dentro de um arquivo .js que está linkado na sua página. E se ele estiver lá largado fora da função "validaReenvio()", não vai ser executado ao clicar no botão de submitar.

 

[]´s

Compartilhar este post


Link para o post
Compartilhar em outros sites

Seria assim:

 

try
  {
	if (camp.value == "")
	  return;
	/* AQUI, SE O CAMPO NAO EXISTIR DA ERRO DE JAVASCRIPT ENTAO CAI PARA O catch */
  }
  catch(e)
  { /* você PODE DEIXAR VAZIO OU EXECUTAR UMA ROTINA */ }

Talvez eu possa ter errad a sintax em algum ponto, pois fiz de cabeça. Mas a idéia é essa, nada q um google não resolva.

 

Então fica desse jeito, dentro do TRY se ocorrer erro por não existir o campo na página imediatamente vai ser executado o código de dentro do catch, que pode estar vazio.

 

Certo!?

 

Boa sorte.

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.