Validação de form
Fala galera,
fiz um formulário em php, que o sistema todo é feito em uma página só, ele não precisa de uma página enviaform.php, por exemplo, para enviar, porém eu estou com dificudades pra fazer a validação dos campos, ja tentei por javascript, fazer um IF, mas nada funciona, não sei porque, alguém pode me dar uma luz?? Segue o código:
<?
$errors = null;
$script = "";
$headers = "";
$area_interessada = str_replace("-", " ", $_GET["script"]);
$area_interessada = str_replace("/", " > ", $area_interessada);
$area_interessada = strtoupper($area_interessada);
function redirect($page) {
echo "<script>location='{$page}';</script>";
exit;
}
$areas = Array(
array("value" => $area_interessada, "text" => "Selecione uma vaga pretendida"),
array("value" => "Analista de Marketing Sr", "text" => "Analista de Marketing Sr"),
array("value" => "Assistente de Loja", "text" => "Assistente de Loja"),
array("value" => "Auxiliar de CPD", "text" => "Auxiliar de CPD"),
array("value" => "Auxiliar de Manutenção", "text" => "Auxiliar de Manutenção"),
array("value" => "Balconista", "text" => "Balconista"),
array("value" => "Caixa", "text" => "Caixa"),
array("value" => "Empacotador", "text" => "Empacotador"),
array("value" => "Estagiário de Marketing", "text" => "Estagiário de Marketing"),
array("value" => "Estoquista", "text" => "Estoquista"),
array("value" => "Faxineiras", "text" => "Faxineiras"),
array("value" => "Líder de Manobrista", "text" => "Líder de Manobrista"),
array("value" => "Manobrista", "text" => "Manobrista"),
array("value" => "Office Boy/Girl", "text" => "Office Boy/Girl"),
array("value" => "Recepcionista", "text" => "Recepcionista"),
array("value" => "Repositor", "text" => "Repositor"),
array("value" => "Segurança", "text" => "Segurança"),
array("value" => "Telefonista", "text" => "Telefonista"),
array("value" => "Vendedores", "text" => "Vendedores")
);
$estados = Array(
array("value" => "São Paulo", "text" => "São Paulo"),
array("value" => "Acre", "text" => "Acre"),
array("value" => "Alagoas", "text" => "Alagoas"),
array("value" => "Amapá", "text" => "Amapá"),
array("value" => "Amazonas", "text" => "Amazonas"),
array("value" => "Bahia", "text" => "Bahia"),
array("value" => "Ceará", "text" => "Ceará"),
array("value" => "Distrito Federal", "text" => "Distrito Federal"),
array("value" => "Goiás", "text" => "Goiás"),
array("value" => "Espirito Santo", "text" => "Espirito Santo"),
array("value" => "Maranhão", "text" => "Maranhão"),
array("value" => "Mato Grosso", "text" => "Mato Grosso"),
array("value" => "Mato Grosso do Sul", "text" => "Mato Grosso do Sul"),
array("value" => "Minas Gerais", "text" => "Minas Gerais"),
array("value" => "Pará", "text" => "Pará"),
array("value" => "Paraiba", "text" => "Paraiba"),
array("value" => "Paraná", "text" => "Paraná"),
array("value" => "Pernambuco", "text" => "Pernambuco"),
array("value" => "Rio de Janeiro", "text" => "Rio de Janeiro"),
array("value" => "Rio Grande do Norte", "text" => "Rio Grande do Norte"),
array("value" => "Rio Grande do Sul", "text" => "Rio Grande do Sul"),
array("value" => "Rondônia", "text" => "Rondônia"),
array("value" => "Rorâima", "text" => "Rorâima"),
array("value" => "Santa Catarina", "text" => "Santa Catarina"),
array("value" => "Sergipe", "text" => "Sergipe"),
array("value" => "Tocantins", "text" => "Tocantins")
);
$civils = Array(
array("value" => "Solteiro", "text" => "Solteiro"),
array("value" => "Casado", "text" => "Casado"),
array("value" => "Divorciado", "text" => "Divorciado")
);
$ingless = Array(
array("value" => "Básico", "text" => "Básico"),
array("value" => "Intermediário", "text" => "Intermediário"),
array("value" => "Fluente", "text" => "Fluente")
);
$espanholl = Array(
array("value" => "Básico", "text" => "Básico"),
array("value" => "Intermediário", "text" => "Intermediário"),
array("value" => "Fluente", "text" => "Fluente")
);
$idiomaa = Array(
array("value" => "Básico", "text" => "Básico"),
array("value" => "Intermediário", "text" => "Intermediário"),
array("value" => "Fluente", "text" => "Fluente")
);
if(isset($_GET["script"])) {
$script = $_GET["script"];
}
if ($act == "enviar"){
$mime_list = array( "html"=>"text/html",
"htm"=>"text/html",
"txt"=>"text/plain",
"rtf"=>"text/enriched",
"csv"=>"text/tab-separated-values",
"css"=>"text/css",
"gif"=>"image/gif",
"doc"=>"application/msword",
"jpeg"=>"image/jpeg",
"jpg"=>"image/jpeg",
"jpe"=>"image/jpeg",
"exe"=>"application/octet-stream",
"mid"=>"audio/midi",
"midi"=>"audio/midi",
"mov"=>"video/quicktime",
"movie"=>"video/x-sgi-movie",
"mp3"=>"audio/mpeg",
"mpeg"=>"video/mpeg",
"mpg"=>"video/mpeg",
"mpga"=>"video/mpeg",
"png"=>"image/png",
"pps"=>"application/mspowerpoint",
"ppt"=>"application/mspowerpoint",
"ppz"=>"application/mspowerpoint",
"qt"=>"video/quicktime",
"ra"=>"audio/x-realaudio",
"rgb"=>"image/x-rgb",
"tif"=>"image/tiff",
"tiff"=>"image/tiff",
"wav"=>"audio/x-wav",
"swf"=>"application/x-shockwave-flash",
"zip"=>"application/zip",
);
$ABORT = FALSE;
if(! ereg("^([0-9,a-z,A-Z]+)(.,_,-)@(.,_,-).{2,3}([0-9,a-z,A-Z])?$", $email ) ) {
echo "Caracteres Inválidos no campo de e-mail!!!";
}
$boundary = "XYZ-" . date(dmyhms) . "-ZYX";
$message = "--$boundary\n";
$message .= "Content-Transfer-Encoding: 8bits\n";
$message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n\n";
$message .= "========= Objetivos =========<br><br>" . "<b>Area de Interesse:</b> " . $_POST["interested_area"] . "<br>" . "<b>Outras Vagas (Caso não tenha na lista):</b> " . $_POST["outras_vagas"] . "<br>" . "<b>Possui Parentes:</b> " . $_POST["parentes1"] . "<br>" . "<b>Parentes na Empresa:</b> " . $_POST["parentes"] . "<br>" . "<b>Pretenção Salarial:</b> " . $_POST["salario"] . "<br>" . "<b>Possui Amigos:</b> " . $_POST["amigo1"] . "<br>" . "<b>Conheçe Algum Funcionario:</b> " . $_POST["amigo"] . "<br>" . "<br><br>======== Informações Pessoais =========<br><br>" . "<b>CPF:</b> " . $_POST["cpf"] . "<br>" . "<b>RG:</b> " . $_POST["rg"] . "<br>" . "<b>Nome:</b> " . $_POST["nome"] . "<br>" . "<b>Sexo:</b> " . $_POST["sexo"] . "<br>" . "<b>Endereço:</b> " . $_POST["endereco"] . "<br>" . "<b>Complemento:</b> " . $_POST["complemento"] . "<br>" . "<b>Bairro:</b> " . $_POST["bairro"] . "<br>" . "<b>Cep:</b> " . $_POST["cep"] . "<br>" . "<b>Cidade:</b> " . $_POST["cidade"] . "<br>" . "<b>Estado:</b> " . $_POST["estado"] . "<br>" . "<b>Tel:</b> " . $_POST["ddd"] . $_POST["tel"] . "<br>" . "<b>Tel Celular:</b> " . $_POST["ddd_cel"] . $_POST["tel_cel"] . "<br>" . "<b>Tel Comercial:</b> " . $_POST["ddd_com"] . $_POST["tel_com"] . "<br>" . "<b>Email:</b> " . $_POST["de"] . "<br>" . "<b>Data de Nascimento:</b> " . $_POST["dia"] . " / " . $_POST["mes"] . " / " . $_POST["ano"] . "<br>" . "<b>Estado Civil:</b> " . $_POST["civil"] . "<br>" . "<br><br>=========Formação Escolar=========<br><br>" . "<b>Entidade:</b> " . $_POST["entidade"] . "<br>" . "<b>Curso:</b> " . $_POST["curso"] . "<br>" . "<b>Inicio:</b> " . $_POST["mes_inicio_curso"] . "/" . $_POST["ano_inicio_curso"] . "<br>" . "<b>Termino:</b> " . $_POST["mes_termino_curso"] . "/" . $_POST["ano_termino_curso"] . "<br><br>======== Conhecimento de Idiomas =========<bR><br>" . "<b>Ingles:</b> " . $_POST["ingles"] . "<br>" . "<b>Espanhol:</b> " . $_POST["espanhol"] . "<br>" . "<b>Outro Idioma:</b> " . $_POST["idioma"] . "<br>" . "<b>Nivel do outro idioma:</b> " . $_POST["idioma1"] . "<br><br>======== Experiencia Profissional =========<br><br>" . "<b>Empresa:</b> " . $_POST["empresa"] . "<br>" . "<b>Função:</b> " . $_POST["funcao"] . "<br>" . "<b>Data de admissão:</b> " . $_POST["admicao_mes"] . " / " . $_POST["admicao_ano"] . "<br>" . "<b>Data de Desligamento:</b> " . $_POST["demissao_mes"] . " / " . $_POST["demissao_ano"] . "<br>" . "<b>Salario:</b> " . $_POST["salario"] . "<br><br>" . "========Arquivo em Anexo========<br><br>";
$message .= "\n";
$attachments[1] = $anexo;
foreach ($attachments as $key => $full_path) {
if ($full_path !='') {
if (file_exists($full_path)){
if ($fp = fopen($full_path,"rb")) {
if ((filesize($full_path)/1024) > "3000"){
echo "O arquivo que você tentou anexar, possui mais que 3MB. Por favor, tente um arquivo menor.";
exit;
}
$filename = array_pop(explode(chr(92),$full_path));
$contents = fread($fp,filesize($full_path));
$encoded = base64_encode($contents);
$encoded_split = chunk_split($encoded);
fclose($fp);
$message .= "--$boundary\n";
$message .= "Content-Type: $anexo_type\n";
$message .= "Content-Disposition: attachment; filename=\"$anexo_name\" \n";
$message .= "Content-Transfer-Encoding: base64\n\n";
$message .= "$encoded_split\n";
}
else {
echo "Impossível abrir o arquivo$key: $filename";
$ABORT = TRUE;
}
}
else {
echo "O arquivo$key não existe: $filename";
$ABORT = TRUE;
}
}
}
$message .= "--$boundary--\r\n";
$assunto = "Contato - Trabalhe Conosco\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: selecao@jorgealex.com.br\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\" charset=iso-8859-1\r\n";
$mensagem = mail($_POST['email'], $assunto, $message, $headers);
redirect("contact_return.php");
}
?>
<body>
<p><?php if($errors) echo($errors); ?></p>
<form name="form1" method="post" enctype="multipart/form-data" action="index.php?act=enviar" onSubmit="return valida();">
<fieldset id="contact">
<b><font size="5">Cadastre seu Currículo</font></b><br><br>
<label for="interested_area">Oportunidades:</label><br>
<select id="interested_area" class="combo" name="interested_area" tabindex="5" style="width:209px;">
<?php
foreach($areas as $package)
{
?>
<option value="<?php echo $package['value']?>" <?php if($script == $package['value'] ) echo("selected") ?> ><?php echo $package["text"]?></option>
<?php
}
?></select><br><br>
<label for="outras_vagas">Digite o nome do cargo para se candidatar a outras vagas:<br></label>
<input id="outras_vagas" type="text" name="outras_vagas" class="string" tabindex="1" maxlength="255" style="width:239px;" value="<?php if($_POST) echo $_POST["outras_vagas"]?>" /><br /><br />
<label for="parentes">Possui algum parente trabalhando atualmente na Jorge Alex:<br></label>
<input name="parentes1" type="radio" value="Sim">Sim
<input name="parentes1" type="radio" value="Nao">Não
Qual? <input id="parentes" type="text" name="parentes" class="string" tabindex="1" maxlength="209" style="width:209px;" value="<?php if($_POST) echo $_POST["parentes"]?>" /><br /><br />
<label for="amigo">Conheçe algum colaborador da Jorge Alex:<br></label>
<input name="amigo1" type="radio" value="Sim">Sim
<input name="amigo1" type="radio" value="Nao">Não
Qual? <input id="amigo" type="text" name="amigo" class="string" tabindex="1" maxlength="255" style="width:209px;" value="<?php if($_POST) echo $_POST["amigo"]?>" /><br /><br />
<label for="salario">Pretensão Salarial (R$ 000,00):<br></label>
<input id="salario" type="text" name="salario" class="string" tabindex="1" maxlength="255" style="width:110px;" value="<?php if($_POST) echo $_POST["salario"]?>" /><br /><br />
<h2><span><hr />Informações Pessoais:</span></h2>
<label for="nome">Nome:</label>
<input id="nome" type="text" name="nome" class="string" tabindex="1" maxlength="255" style="width:269px;" value="<?php if($_POST) echo $_POST["nome"]?>" /><br /><br />
<label for="cpf">CPF:</label>
<input id="cpf" type="text" name="cpf" class="string" tabindex="1" maxlength="255" style="width:100px;" value="<?php if($_POST) echo $_POST["cpf"]?>" />
<label for="rg">RG:</label>
<input id="rg" type="text" name="rg" class="string" tabindex="1" maxlength="255" style="width:100px;" value="<?php if($_POST) echo $_POST["rg"]?>" /><br /><br />
<label for="sexo">Sexo:</label>
<input name="sexo" type="radio" value="Feminino" />Feminino
<input name="sexo" type="radio" value="Masculino" />Masculino
<br /><br />
<label for="endereco">Endereço:</label>
<input id="endereco" type="text" name="endereco" class="string" tabindex="1" maxlength="255" style="width:269px;" value="<?php if($_POST) echo $_POST["endereco"]?>" />
<label for="complemento">Complemento:</label>
<input id="complemento" type="text" name="complemento" class="string" tabindex="1" maxlength="255" style="width:90px;" value="<?php if($_POST) echo $_POST["complemento"]?>" /><br /><br />
<label for="bairro">Bairro:</label>
<input id="bairro" type="text" name="bairro" class="string" tabindex="1" maxlength="255" style="width:159px;" value="<?php if($_POST) echo $_POST["bairro"]?>" />
<label for="cep">Cep:</label>
<input id="cep" type="text" name="cep" class="string" tabindex="1" maxlength="255" style="width:85px;" value="<?php if($_POST) echo $_POST["cep"]?>" /><br /><br />
<label for="cidade">Cidade:</label>
<input id="cidade" type="text" name="cidade" class="string" tabindex="1" maxlength="255" style="width:159px;" value="<?php if($_POST) echo $_POST["cidade"]?>" />
<label for="estado">Estado:</label>
<select id="estado" class="combo" name="estado" tabindex="5" style="width:129px;">
<?php
foreach($estados as $package)
{
?>
<option value="<?php echo $package['value']?>" <?php if($script == $package['value'] ) echo("selected") ?> ><?php echo $package["text"]?></option>
<?php
}
?></select><br>
<table width="622" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="221">Telefone Residencial<br />
<label for="ddd">DDD:</label>
<input id="ddd" type="text" name="ddd" class="string" tabindex="1" maxlength="255" style="width:35px;" value="<?php if($_POST) echo $_POST["ddd"]?>" />
<label for="tel">Tel:</label>
<input id="tel" type="text" name="tel" class="string" tabindex="1" maxlength="255" style="width:100px;" value="<?php if($_POST) echo $_POST["tel"]?>" /></td>
<td width="13"> </td>
<td width="366">Telefone Celular<br />
<label for="ddd_cel">DDD:</label>
<input id="ddd_cel" type="text" name="ddd_cel" class="string" tabindex="1" maxlength="255" style="width:35px;" value="<?php if($_POST) echo $_POST["ddd_cel"]?>" />
<label for="tel_cel">Tel:</label>
<input id="tel_cel" type="text" name="tel_cel" class="string" tabindex="1" maxlength="255" style="width:100px;" value="<?php if($_POST) echo $_POST["tel_cel"]?>" /></td>
</tr>
<td><tr> </tr></td>
<tr>
<td>Telefone p/ Recados<br />
<label for="ddd_com">DDD:</label>
<input id="ddd_com" type="text" name="ddd_com" class="string" tabindex="1" maxlength="3" style="width:35px;" value="<?php if($_POST) echo $_POST["ddd_com"]?>" />
<label for="tel_com">Tel:</label>
<input id="tel_com" type="text" name="tel_com" class="string" tabindex="1" maxlength="10" style="width:100px;" value="<?php if($_POST) echo $_POST["tel_com"]?>" /></td>
<td> </td>
<td> </td>
</tr>
</table><br>
<label for="email">E-mail:</label>
<input id="de" type="text" name="de" class="de" tabindex="2" maxlength="265" style="width:225px;" value="<?php if($_POST) echo $_POST["de"]?>"/><br /><br />
Data de Nascimento:<br />
<input id="dia" type="text" name="dia" class="string" tabindex="1" maxlength="255" style="width:25px;" value="<?php if($_POST) echo $_POST["dia"]?>" />
<label for="mes">/</label>
<input id="mes" type="text" name="mes" class="string" tabindex="1" maxlength="255" style="width:25px;" value="<?php if($_POST) echo $_POST["mes"]?>" />
<label for="ano">/</label>
<input id="ano" type="text" name="ano" class="string" tabindex="1" maxlength="255" style="width:35px;" value="<?php if($_POST) echo $_POST["ano"]?>" />
dia / mes / ano<br /><br />
<label for="civil">Estado Civil: </label><select id="civil" class="combo" name="civil" tabindex="5" style="width:100px;">
<?php
foreach($civils as $package)
{
?>
<option value="<?php echo $package['value']?>" <?php if($script == $package['value'] ) echo("selected") ?> ><?php echo $package["text"]?></option>
<?php
}
?></select><br><br />
<hr /><h2><span>Formação Escolar</span></h2></hr>
<label for="entidade">Entidade:</label>
<input id="entidade" type="text" name="entidade" class="string" tabindex="1" maxlength="255" style="width:250px;" value="<?php if($_POST) echo $_POST["entidade"]?>" /><br><br>
<label for="curso">Curso:</label>
<input id="curso" type="text" name="curso" class="string" tabindex="1" maxlength="255" style="width:250px;" value="<?php if($_POST) echo $_POST["curso"]?>" /><br><br>
Data de Inicio:<br>
<input id="mes_inicio_curso" type="text" name="mes_inicio_curso" class="string" tabindex="1" maxlength="255" style="width:25px;" value="<?php if($_POST) echo $_POST["mes_inicio_curso"]?>" />
<label for="ano_inicio_curso">/</label>
<input id="ano_inicio_curso" type="text" name="ano_inicio_curso" class="string" tabindex="1" maxlength="255" style="width:35px;" value="<?php if($_POST) echo $_POST["ano_inicio_curso"]?>" /> mês / ano<br /><br />
Data de Conclusão:<br>
<input id="mes_termino_curso" type="text" name="mes_termino_curso" class="string" tabindex="1" maxlength="255" style="width:25px;" value="<?php if($_POST) echo $_POST["mes_termino_curso"]?>" />
<label for="ano_termino_curso">/</label>
<input id="ano_termino_curso" type="text" name="ano_termino_curso" class="string" tabindex="1" maxlength="255" style="width:35px;" value="<?php if($_POST) echo $_POST["ano_termino_curso"]?>" /> mês / ano<br /><br />
<hr /><h2><span>Conhecimento de Idiomas</span></h2></hr>
<label for="ingles">Inglês:</label><br>
<select id="ingles" class="combo" name="ingles" tabindex="5" style="width:105px;">
<?php
foreach($ingless as $package)
{
?>
<option value="<?php echo $package['value']?>" <?php if($script == $package['value'] ) echo("selected") ?> ><?php echo $package["text"]?></option>
<?php
}
?></select><br />
<label for="espanhol">Espanhol:</label><br>
<select id="espanhol" class="combo" name="espanhol" tabindex="5" style="width:105px;">
<?php
foreach($espanholl as $package)
{
?>
<option value="<?php echo $package['value']?>" <?php if($script == $package['value'] ) echo("selected") ?> ><?php echo $package["text"]?></option>
<?php
}
?></select><br />
<label for="idioma">Outro Idioma: (opcional)<br /></label>
<input id="idioma" type="text" name="idioma" class="string" tabindex="1" maxlength="255" style="width:139px;" value="<?php if($_POST) echo $_POST["idioma"]?>" /><br />
<select id="idioma1" class="combo" name="idioma1" tabindex="5" style="width:105px;">
<?php
foreach($idiomaa as $package)
{
?>
<option value="<?php echo $package['value']?>" <?php if($script == $package['value'] ) echo("selected") ?> ><?php echo $package["text"]?></option>
<?php
}
?></select><br /><br />
<hr /><h2><span>Experiencia Profissional:</span></h2></hr>
<label for="empresa">Empresa:</label>
<input id="empresa" type="text" name="empresa" class="string" tabindex="1" maxlength="255" style="width:259px;" value="<?php if($_POST) echo $_POST["empresa"]?>" /><br /><br />
<label for="funcao">Função:</label>
<input id="funcao" type="text" name="funcao" class="string" tabindex="1" maxlength="255" style="width:259px;" value="<?php if($_POST) echo $_POST["funcao"]?>" /><br /><br />
<label for="admicao">Data de Admissão:</label>
<input id="admicao_mes" type="text" name="admicao_mes" class="string" tabindex="1" maxlength="255" style="width:25px;" value="<?php if($_POST) echo $_POST["admicao_mes"]?>" />
/ <input id="admicao_ano" type="text" name="admicao_ano" class="string" tabindex="1" maxlength="255" style="width:35px;" value="<?php if($_POST) echo $_POST["admicao_ano"]?>" /><br /><Br />
<label for="demissao">Data de Desligamento:</label>
<input id="demissao_mes" type="text" name="demissao_mes" class="string" tabindex="1" maxlength="255" style="width:25px;" value="<?php if($_POST) echo $_POST["demissao_mes"]?>" />
/ <input id="demissao_ano" type="text" name="demissao_ano" class="string" tabindex="1" maxlength="255" style="width:35px;" value="<?php if($_POST) echo $_POST["demissao_ano"]?>" /><br /><Br />
<label for="salario">Salário:</label>
<input id="salario" type="text" name="salario" class="string" tabindex="1" maxlength="255" style="width:129px;" value="<?php if($_POST) echo $_POST["salario"]?>" /><br /><br />
<hr>
<label for="salario1">Se preferir, você também pode anexar seu Curriculo:</label><br><br>
<input type="file" name="anexo"><br>
O arquivo deverá ter no máximo 1Mb. </p>
<input type="hidden" value="leonardo@kwcompany.com.br" name="email">
<p align="center" class="style2" style="word-spacing: 0; margin: 0">
<input type="submit" name="submit" value="Enviar">
</p>
</form>Abraços!
;)
Discussão (13)
Carregando comentários...