0

Hi,

I'm doing a registration system and as you can see when i verify the fields, if it's empty it says that the FIELD_1 misses. And what i want is if the field is empty says that and then goes back, but i don't wanto the info already written disappears.

registration

<?PHP

include 'topo.php';

?>


<!-- content -->

   <div class="indent">

        <h2> Inscrição </h2>


<form action="envia.php" method="post" onsubmit="return validar()" >
  <fieldset>
   <legend> ALUNO </legend>
       
          <br/>
          <div class="field"><label>Username*: </label><input type="text" size="30" name = "username"/></div>
      <br/>      
          <div class="field"><label>Password*: </label><input type="password" size="25" name = "pass"/></div>
      <br/>      
          <div class="field"><label>Confirma Password*: </label><input type="password" size="25" name = "conf_pass"/></div>
      <br/>      
          <div class="field"><label>Nome*: </label><input type="text" size="40" name = "nome"/></div>
      <br/>      
      <div class="field"><label>Data de Nascimento*: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="3" maxlength="2" name = "dia"/> / <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="3" maxlength="2" name = "mes"/> / <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="5" maxlength="4" name = "ano"/>  (DD/MM/AAAA)</div>
      <br/>
      <div class="field"><label>Morada: </label><input type="text" onkeypress="return onlyNumbers();" size="39" name = "morada"/></div>
      <br/>
      <div class="field"><label>Código Postal: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="5" maxlength="4" name = "cp1"/> - <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="4" maxlength="3" name = "cp2"/></div>
      <br/>
      <div class="field"><label>Telemóvel*: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="10" maxlength="9" name = "tele"/></div>
      <br/>
          Curso*: <select name="curso">
          <option value = 1> Piano    </option>
          <option value = 2> Orgão    </option>
          <option value = 3> Guitarra Elétrica </option>
          <option value = 4> Guitarra Acústica </option>
          <option value = 5 Violino  </option>
          <option value = 6> Canto    </option>
          <option value = 7> Bateria  </option>
          <option value = 8> Saxofone </option>
          <option value = 9> Flauta   </option>
          <option value = 10> Baixo </option>
           <option value = 11> Violoncelo </option>
          </select>
          <br/>
          <br/>
      <div class="field"><label>E-Mail*: </label><input type="text" value="" name = "email" size = "25"/></div>
          <br/>
          Observações:
          <br/>
      <textarea cols="30" rows="7" name="obs"></textarea>
  </fieldset>
  <br/>
  <fieldset>
    <legend> ENCARREGADO DE EDUCAÇÃO  </legend>
         
          <br/>
      <div class="field"><label>Nome*: </label><input type="text" size="40" name = "nome_ee"/></div>
      <br/>
      <div class="field"><label>Morada: </label><input type="text" size="39" name = "morada_ee"/></div>
      <br/>
          <div class="field"><label>Código Postal: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="5" maxlength="4" name = "cp1_ee"/> - <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="4" maxlength="3" name = "cp2_ee"/></div>
          <br/>
      <div class="field">Telemóvel*: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="10" maxlength="9" name = "tele_ee"/></div>
      <br/>
      <div class="field"><label>E-Mail*: </label><input type="text" value="" name = "email_ee" size = "25"/></div>
         
  </fieldset>
      <br/>
      * Campos Obrigatórios
          <br/>
          <input type="submit" value="Enviar">
      <input type="Reset" value="Apagar">
 
</form>
       
   </div>
</div>


<?PHP

include 'rodape.php';

?>

send

<?PHP

//ligar base de dados

include "db_connect.php";

/////////// ALUNO ///////////////
$username = $_POST ['username'];
$pass = $_POST ['pass'];
$conf_pass = $_POST ['conf_pass'];
$nome = $_POST ['nome'];
$dia = $_POST ['dia'];
$mes = $_POST ['mes'];
$ano = $_POST ['ano'];
$data_nascimento = $dia .'-'. $mes .'-'. $ano;
$morada = $_POST ['morada'];
$cp1 = $_POST ['cp1'];
$cp2 = $_POST ['cp2'];
$cp_aluno = $cp1 .'-'. $cp2;
$curso = $_POST ['curso'];
$telemovel = $_POST ['tele'];
$email = $_POST ['email'];
$observacao = $_POST ['obs'];

///////////ENC.EDU.///////////////
$nome_ee = $_POST ['nome_ee'];
$morada_ee = $_POST ['morada_ee'];
$cp1_ee = $_POST ['cp1_ee'];
$cp2_ee = $_POST ['cp2_ee'];
$cp_ee = $cp1_ee .'-'. $cp2_ee;
$tele_ee = $_POST ['tele_ee'];
$email_ee = $_POST ['email_ee'];

include 'veref_aluno.php';
include 'veref_ee.php';

//inserir na base de dados

$sql = "INSERT INTO alunos (username, password, nome_aluno, data_nascimento, morada_aluno, cp_aluno, telemovel_aluno, email_aluno, observacoes, nome_ee, morada_ee, cp_ee, telemovel_ee, email_ee)
                VALUES('". $username. "', '" . $pass ."','" . $nome ."', '". $data_nascimento ."', '". $morada ."', '". $cp_aluno ."', '". $telemovel ."', '". $email ."','" .  $observacao . "','". $nome_ee ."', '". $morada_ee ."', '". $cp_ee ."', '". $tele_ee ."', '". $email_ee ."')";

if(mysql_query($sql))
{
 echo "Inscrição feita com sucesso. Em breve receberá um email para confirmar os dados. Obrigado!";
 //header ('Location: index.php');
}
 
?>

veref_reg student

<?PHP

$back = $_SERVER['HTTP_REFERER'];

// verifica username
if (empty($username))
{
 die("<script>alert(\"Preencha o Username.\");
 location.href='". $back ."';
 </script>");
 
}

// verifica password
if (empty($pass))
{
 die("Preencha a 'Password'.");
}
   
//verifica conf_pass


// verifica nome
if (empty($nome))
{
 die("Preencha o 'Nome'.");
}

//verifica telemovel
if (empty($telemovel))
{
 die("Preencha o 'Telemovel'.");
}

// verifica email
if (empty($email))
{
 die("Preencha 'Email'.");
}
?>

Do you understand?

If you do, can you help me?

Thank you,
PF2G

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by PF2G
0

First of all you should do a JavaScript with return false; for not letting the script to go further.
You should do a verification by PHP as well

0

why do you want to take the empty variables to the next page

just check it with js or jquery on form submission and set the return value to false if there are empty fields.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js">
</script>
<script type="text/javascript" >
$(function() {
$(".submit").click(function() {   //onsubmission of the form

     if($("#fieldname").val()=="")   //#fieldname is the text field id
     {
         return false;
     }
     else
    {
         return true;
     }

});

});
</script>
0

why do you want to take the empty variables to the next page

just check it with js or jquery on form submission and set the return value to false if there are empty fields.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js">
</script>
<script type="text/javascript" >
$(function() {
$(".submit").click(function() {   //onsubmission of the form

     if($("#fieldname").val()=="")   //#fieldname is the text field id
     {
         return false;
     }
     else
    {
         return true;
     }

});

});
</script>

Wai a minute, this code for each field?

0

why do you want to take the empty variables to the next page

just check it with js or jquery on form submission and set the return value to false if there are empty fields.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js">
</script>
<script type="text/javascript" >
$(function() {
$(".submit").click(function() {   //onsubmission of the form

     if($("#fieldname").val()=="")   //#fieldname is the text field id
     {
         return false;
     }
     else
    {
         return true;
     }

});

});
</script>

I'm using ajax, i never worked with it, so i'm gonna ask you if i'm doing everything ok:


registration form:

<!---------VALIDAÇÃO AJAX---------->
<link rel="stylesheet" type="text/css" href="style_val.css" />
<script src="ajaxforms.js" type="text/javascript" language="javascript"></script>
<!--------------------------------->
<div class="indent">

 <h2> Inscrição </h2>

<form action="" method="post">
  <fieldset>
   <legend> ALUNO </legend>
	
	  <br/>
	  <div class="title" class="field"><label>Username*: </label><input type="text" size="30" name = "username" OnChange="CheckField(this)" tabindex="1"/></div>
	  <div id="username" class="message"></div>

ajaxform:

var AJAXForms = false;
var LastField = null;
var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	AJAXForms = new XMLHttpRequest();
}

function CheckField(field) {

	if (window.XMLHttpRequest) {
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		AJAXForms = new ActiveXObject("Microsoft.XMLHTTP");
	}

  AJAXForms.onreadystatechange = processChange;
  AJAXForms.open("GET", "check.php?op=ajax&field=" +field.name+"&value=" + field.value);
  LastField = field.name;
  AJAXForms.send(null);
}

function processChange() {
  if (AJAXForms.readyState == 4) { 
  
    var  res = document.getElementById(LastField);
    res.innerHTML = AJAXForms.responseText;
    res.style.visibility = "visible";
    
  }
}

style:

body,* {
	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
	font-size: 12px;
}

.ajform {
	background: #FF7F50;
    border:1px solid black;
	padding: 4px;
	margin: 4px;
	width: 500px;
}

.title {
	width: 60%;
	background: #FFAF91;
	padding: 4px;
}

.field {
	padding: 4px;
	background: #FFE691;	
}

.message {
	background: white;
	border:1px solid #FF7F50;
	visibility: hidden;
	margin: 4px;
	text-align: center;
}

.green {
	color: Green;
}

.red {
	color: red;
}

.category {
	background: #E0FF91;
	padding: 4px;
}

Please help me.

Thank you,
PF2G

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.