[Resolvido] Trabalhando com Classes
Pessoal, Estou com dificuldades em enviar os dados do formulário para a função responsável pelo cadastro...Esta função esta dentro de uma classe.. Mas não estou conseguinto passar os dados do formulario para a função..
O formulario
<?php
require_once "eventos.php";
//verifica qual botão foi selecionado pelo usuario ----------------------------------------
if ($_POST) {
$cad = new Eventos();
$cad->cadastrar($_POST['selectnoticia'],$_POST['descriao']);
}
?>
<!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">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gerenciador de Conteúdo | Página Principal</title>
<style type="text/css"><!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}-->
</style>
<script>
function verifica(frm)// TRECHO JAVASCRIPT PARA VERIFICAR O CAMPO "NOME" --- INICIO
// Verifica o campo NOME SECAO.
{
{
var str = frm.descricao.value
// Verifica se foram digitados mais de 10 caracteres.
if (str.length > 50)
{
alert("\nO campo Descrição está limitado a\n\n80caracteres ")
// form.nome.focus();
return false;
}
// Return false se o campo NOME estiver vazio.
if (str == " " )
{
alert("\nO campo Descrição em branco.\n\nPor favor entre com a Descrição.");
// form.nome.focus();
return false;
}
if (str == "" )
{
alert("\nO campo Descrição está em branco.\n\nPor favor entre com a Descrição.")
// form.nome.focus();
return false;
}
}
return true;
}
}
</script>
<link href="estilos/estilo.css" rel="stylesheet" type="text/css" />
</head>
<body><?php include "topo.php"; ?>
<form name= "form" action="formevento_cadastro.php" method="post" onSubmit="return verifica(this)">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="40" class="barratituloarea"><img src="graficos/icon_edit.png" width="32" height="32" border="0" align="absmiddle" />Incluir Evento </td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="tableconteudo">
<tr valign="bottom">
<td class="titulocampo"><label></label></td>
</tr>
<tr valign="bottom" class="titulocampo">
<td>Selecione uma Notícia </td>
</tr>
<tr>
<td><label>
<select name="selectnoticia" id="selectnoticia" >
<?php
//listando as seções no combobox
include 'conexao/conexao.php';
$query = "select * from noticias where ativar_noticia = 'sim' order by titulo_noticia";
$resposta= mysql_query("$query");
while ($dados=mysql_fetch_array($resposta)) {
if ($_GET['selectnoticia'] == $dados['cod_notivia']) { $selected = 'selected'; $ha = 1; } else { $selected=''; }
$saida .= '<option value="'.$dados['cod_noticia'].'" '.$selected.'>'.$dados['titulo_noticia'].'</option>';
}
echo '<option '.(($ha)?'':'selected').'>Selecione uma Notícia</option>'.$saida;
mysql_close($connect);
?>
</label></td>
</tr>
<tr valign="bottom" class="titulocampo">
<td>Descricção do Evento :</td>
</tr>
<tr>
<td><label>
<input name="descricao" type="text" id="descricao" value = ""size="80" />
</label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><label>
<input type="submit" name="salvar" id="salvar" value="Salvar" />
</label></td>
</tr>
</table>
</form>
</body>
</html>A classe:
<?php
set_time_limit(0);class Eventos{
var $codnoticia = "";
var $descricaoaviso = "";
function cadastrar($noticia,$descricao){
//CADASTRANDO UMA NOTICIA
$query = "insert into eventos(
cod_noticia,
descricao)
values(
'$noticia',
'$descricao')";
//echo $query;
$result = mysql_query($query);
if(!$result){
echo '<script>alert("\nErro ao efetuar o cadastro!")
</script>';
/// echo "<meta HTTP-EQUIV='refresh' CONTENT='1;URL=formnoticia_cadastro.php'>";
mysql_close($connect);
}else{
echo '<script>alert("\nCadastro Efetuado com Sucesso!")
</script>';
// echo "<meta HTTP-EQUIV='refresh' CONTENT='1;URL=formnoticia_cadastro.php'>";
mysql_close($connect);
}
}
}
?>Discussão (4)
Carregando comentários...