Ir para conteúdo

Arquivado

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

Turetto

Validar campos no Formulario.php

Recommended Posts

Olá pessoal, seguinte, tenho uma pagina em php com o nome licitacao.php, nela existe três tipo de visualizações, mais o que eu to querendo agora e o seguinte, se falta um campo dos obrigatorios não enviar para o banco.

 

Como faço isso, em que parte do corpo devo colocar alguma aplicação em JS....

 

O codigo é esse, vou colocar ele todo.....

 

<?php require_once('Connections/cigas.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "adm";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
	// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
	// Parse the strings into arrays. 
	$arrUsers = Explode(",", $strUsers); 
	$arrGroups = Explode(",", $strGroups); 
	if (in_array($UserName, $arrUsers)) { 
	  $isValid = true; 
	} 
	// Or, you may restrict access to only certain users based on their username. 
	if (in_array($UserGroup, $arrGroups)) { 
	  $isValid = true; 
	} 
	if (($strUsers == "") && false) { 
	  $isValid = true; 
	} 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "intranet.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
	case "text":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	  break;	
	case "long":
	case "int":
	  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
	  break;
	case "double":
	  $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
	  break;
	case "date":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	  break;
	case "defined":
	  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
	  break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  $insertSQL = sprintf("INSERT INTO licitacoes (tit_lic, dat_lic, num_lic, hor_lic, obj_lic, sit_lic, res_lic, tel_lic, ema_lic, sta_lic, dat_pub_lic, dat_abe_lic, dat_fec_lic, val_est, val_lic, ven_lic, hor_abe_lic) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
					   GetSQLValueString($_POST['tit_lic'], "text"),
					   GetSQLValueString($_POST['Dat_lic'], "date"),
					   GetSQLValueString($_POST['num_lic'], "text"),
					   GetSQLValueString($_POST['hor_lic'], "date"),
					   GetSQLValueString($_POST['obj_lic'], "text"),
					   GetSQLValueString($_POST['sit_lic'], "text"),
					   GetSQLValueString($_POST['res_lic'], "text"),
					   GetSQLValueString($_POST['tel_lic'], "text"),
					   GetSQLValueString($_POST['ema_lic'], "text"),
					   GetSQLValueString($_POST['sta_lic'], "text"),
					   GetSQLValueString($_POST['dat_pub_lic'], "date"),
					   GetSQLValueString($_POST['dat_abe_lic'], "date"),
					   GetSQLValueString($_POST['dat_fec_lic'], "date"),
					   GetSQLValueString($_POST['val_est'], "text"),
					   GetSQLValueString($_POST['val_lic'], "text"),
					   GetSQLValueString($_POST['ven_lic'], "text"),
					   GetSQLValueString($_POST['hor_abe_lic'], "date"));

  mysql_select_db($database_cigas, $cigas);
  $Result1 = mysql_query($insertSQL, $cigas) or die(mysql_error());

  $insertGoTo = "cad_lic.php";
  if (isset($_SERVER['QUERY_STRING'])) {
	$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
	$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$data = date("y-m-d");  
$hora = date("H:i:s"); 
?>

<!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>Companhia de Gás do Amazonas - Cigás</title>
<style type="text/css">
<!--
a:link {
	color: #000066;
	text-decoration: none;
}
a:visited {
	color: #000066;
	text-decoration: none;
}
a:hover {
	color: #000066;
	text-decoration: underline;
}
a:active {
	color: #000066;
	text-decoration: none;
}
body,td,th {
	color: #666666;
}
.style40 {color: #FFFFFF; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
.style41 {color: #000000}
body {
	background-image: url();
	background-color: #FFFFFF;
}
.style45 {
	font-family: Arial, Helvetica, sans-serif;
	color: #000066;
	font-weight: bold;
	font-size: 17px;
}
.style46 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
.style47 {color: #000066}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onload="MM_preloadImages('imagens/Fig_Email2.gif')">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="missao">
  <tr>
	<td><div align="center">
	<label></label>
	
	<div align="left"><span class="style45">Cadastro de Licitação </span></div>
	<div align="center"></div></td>
  </tr>
</table>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form" id="form">
  <table width="100%" border="1" align="center" cellpadding="0" cellspacing="2" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td width="25%" height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Titulo:</div>
	  </div></td>
	  <td width="75%" height="25" bgcolor="#FFFFFF"><input name="tit_lic" type="text" id="tit_lic" size="50" maxlength="50" />
		  <input name="Dat_lic" type="hidden" id="Dat_lic2" value="<?php echo $data; ?>" />
		  <input name="hor_lic" type="hidden" id="hor_lic2" value="<?php echo $hora; ?>" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td width="25%" height="11" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Número:</div>
	  </div></td>
	  <td width="75%" height="11" bgcolor="#FFFFFF"><input name="num_lic" type="text" id="num_lic" size="50" maxlength="10" />
	  </td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td width="25%" height="12" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Data da Publicação:</div>
	  </div></td>
	  <td height="12" bgcolor="#FFFFFF"><input name="dat_pub_lic" type="text" id="dat_pub_lic" size="50" maxlength="10" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Data Abertura:</div>
	  </div></td>
	  <td width="75%" height="25" bgcolor="#FFFFFF"><input name="dat_abe_lic" type="text" id="dat_abe_lic" size="50" maxlength="50" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left">  Hora Abertura:</div>
	  </div></td>
	  <td width="75%" height="25" bgcolor="#FFFFFF"><input name="hor_abe_lic" type="text" id="hor_abe_lic" size="50" maxlength="50" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td width="25%" height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Objeto:</div>
	  </div></td>
	  <td width="75%" height="25" bgcolor="#FFFFFF"><label>
		<textarea name="obj_lic" cols="50" rows="5" id="obj_lic"></textarea>
	  </label></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Valor Estimado:</div>
	  </div></td>
	  <td height="25" bgcolor="#FFFFFF"><input name="val_est" type="text" id="val_est" size="50" maxlength="25" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Responsável:</div>
	  </div></td>
	  <td width="75%" height="25" bgcolor="#FFFFFF"><input name="res_lic" type="text" id="res_lic" size="50" maxlength="25" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Telefone:</div>
	  </div></td>
	  <td width="75%" height="25" bgcolor="#FFFFFF"><input name="tel_lic" type="text" id="tel_lic" size="50" maxlength="25" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> E-mail:</div>
	  </div></td>
	  <td width="75%" height="25" bgcolor="#FFFFFF"><input name="ema_lic" type="text" id="ema_lic" size="50" maxlength="25" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Situação</div>
	  </div></td>
	  <td height="25" bgcolor="#FFFFFF"><textarea name="sit_lic" cols="50" rows="5" id="sit_lic"></textarea></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Data de Fechamento:</div>
	  </div></td>
	  <td height="25" bgcolor="#FFFFFF"><input name="dat_fec_lic" type="text" id="dat_fec_lic" size="50" maxlength="50" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Vencedor:</div>
	  </div></td>
	  <td height="25" bgcolor="#FFFFFF"><input name="ven_lic" type="text" id="ven_lic" size="50" maxlength="25" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Valor da Licitação:</div>
	  </div></td>
	  <td height="25" bgcolor="#FFFFFF"><input name="val_lic" type="text" id="val_lic" size="50" maxlength="25" /></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style47">
		  <div align="left"> Status:</div>
	  </div></td>
	  <td height="25" bgcolor="#FFFFFF"><select name="sta_lic" id="sta_lic">
		  <option value="Inativo">Selecione um</option>
		  <option value="Novas">Novas</option>
		  <option value="Andamento">Andamento</option>
		  <option value="Encerradas">Encerradas</option>
	  </select></td>
	</tr>
	<tr bordercolor="#000000" bgcolor="#DBDBDB">
	  <td height="25" bgcolor="#DBDBDB"><div align="center" class="style40 style41">
		  <div align="left"> <span class="style47">Arquivo:</span></div>
	  </div></td>
	  <td height="25" bgcolor="#FFFFFF"><label>
		<input name="arq_lic" type="file" id="arq_lic" />
	  </label></td>
	</tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
<input type="hidden" name="MM_insert" value="form" />
</form>
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="2" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
  <tr bordercolor="#000000" bgcolor="#DBDBDB">
	<td width="50%" height="25" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><label></label></td>
	<td width="20%" height="25" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
	<td width="10%" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> </td>
	<td width="10%" bordercolor="#000000" bgcolor="#FFFFFF"><div align="center" class="style46"><a href="java script:document.form.submit()">Salvar</a></div>
	  <a href="cont_index.php"></a></td>
	<td width="10%" bgcolor="#FFFFFF"><div align="center" class="style46"><a href="cont_lic.php">Voltar</a></div></td>
  </tr>
</table>
<p> </p>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Crie uma função para validar os campos do form, coloque entre as tags <head> e </head>.

 

Na tag form, coloque o evento onSubmit para verificar os dados ao enviar o formulário.

 

Sobre validação, tem diversos tópicos no fórum.

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.