Problem validating inputbody - *LONG*

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paolo
Forum Newbie
Posts: 15
Joined: Sat May 14, 2005 6:06 am

Problem validating inputbody - *LONG*

Post by paolo »

Hello to everybody,
I'm new to php world, just fallen deeply into a week ago for a job given to me, my problm is the follow:
- I've got a form, with 22 field, 9 of wich need to be inserted (other 13 are optional)
- I use sessions since user must be autenthicated and this have been done.
- I've the main form anagrafica_ins0.php where I simply create the form than pass data to anagrafica_ins1.php using POST command
- anagrafica_ins1.php simply takes the parameters and save them into session variable

Code: Select all

$ragsociale1 = $_POST['ragsociale1'];		//*
	$ragsociale2 = $_POST['ragsociale2'];
	$indirizzo = $_POST['indirizzo'];		//*
	$cap = $_POST['cap'];		//*
	$citta = $_POST['citta'];		//*
	$provincia = $_POST['provincia'];		//*
	$modauto = $_POST['modauto'];		//*
..
then passed it to anagrafica_ins2.php
- In this file I do a check to verifyif all the 9 field has been inserted and if not I generate a new form where I ask to reinsert needed one.
Here is the file anagrafica_ins2.php

Code: Select all

<?php
session_start();


if ($_SESSION['logged']) 		//se siamo loggati prosegui col form
{
	echo"sessione aperta";
	global $PHP_SELF;
	$all_needed_set=0;
	//Verranno marchiati con * i campi ritenut obbligatori
	$ragsociale1 = $_SESSION['ragsociale1'];		//*
	$ragsociale2 = $_SESSION['ragsociale2'];
	$indirizzo = $_SESSION['indirizzo'];		//*
	$cap = $_SESSION['cap'];		//*
	$citta = $_SESSION['citta'];		//*
	$provincia = $_SESSION['provincia'];		//*
	$modauto = $_SESSION['modauto'];		//*
	$targaauto = $_SESSION['targaauto'];		//*
	$garanzia = $_SESSION['garanzia'];
	$circolare = $_SESSION['circolare'];
	$telefono = $_SESSION['telefono'];		//*
	$cellulare = $_SESSION['cellulare'];
	$email = $_SESSION['email'];
	$kmanno = $_SESSION['kmanno'];		//*
	$dtnextcirc = $_SESSION['dtnextcirc'];
	$dtproxcntr = $_SESSION['dtproxcntr'];
	$servizioneve = $_SESSION['servizioneve'];
	$qtgommeneve = $_SESSION['qtgommeneve'];
	$stampa_garanzia = $_SESSION['stampa_garanzia'];
	$stampa_circolare = $_POST['stampa_circolare'];
	$sede = $_SESSION['sede'];




	if(!$all_needed_set)				//se non sono state settate tutte le variabili oppure è la primavolta, verifichiamo
	{
		
		echo"$cap";
		if( (empty($ragsociale1)) || (empty($indirizzo)) || (empty($cap))
			|| (empty($citta)) || (empty($provincia)) || (empty($modauto))
			|| (empty($targaauto)) || (empty($telefono)) || (empty($kmanno)) )
		{
			$all_needed_set=0;

			echo"<center><h2>Inserire i campi mancanti</h2></center>
				<form method=\"post\" action=\"anagrafica_ins1.php\">
				<table cellspacing=\"2\" cellpadding=\"5\" width=\"40%\" border=\"1\" align=\"left\">";
				
			if(empty($ragsociale1))
					{		echo "<th align=\"left\" width=\"30%\">Rag. Sociale 1</th>
					<td width=\"50%\"><input size=\"30\" name=\"ragsociale1\"></td>";
			}
			if(empty($indirizzo))
			{		echo "<tr><th align=\"left\" width=\"30%\">Indirizzo</th>
					<td width=\"50%\"><input size=\"30\" name=\"indirizzo\"></td></tr>";
			}
			if(empty($cap))
			{		echo "<tr><th align=\"left\" width=\"30%\">CAP</th>
					<td width=\"50%\"><input size=\"7\" name=\"cap\"></td></tr>";
			}
			if(empty($citta))
			{		echo "<tr><th align=\"left\" width=\"30%\">Città</th>
					<td width=\"50%\"><input size=\"30\" name=\"citta\"></td></tr>";
			}
			if(empty($provincia))
			{		echo "<tr><th align=\"left\" width=\"30%\">Provincia</th>
					<td width=\"50%\"><input size=\"7\" name=\"provincia\"></td></tr>";
			}
			if(empty($modauto))
			{		echo "<tr><th align=\"left\" width=\"30%\">Modello Auto</th>
					<td width=\"50%\"><input size=\"20\" name=\"modauto\"></td></tr>";
			}
			if(empty($targaauto))
			{		echo "<tr><th align=\"left\" width=\"30%\">Targa Auto</th>
					<td width=\"50%\"><input size=\"20\" name=\"targaauto\"></td></tr>";
			}
			if(empty($telefono))
			{		echo "<tr><th align=\"left\" width=\"30%\">Telefono</th>
					<td width=\"50%\"><input size=\"20\" name=\"telefono\"></td></tr>";
			}
			if(empty($kmanno))
			{		echo "<tr><th align=\"left\" width=\"30%\">Chilometri Anno</th>
					<td width=\"50%\"><input size=\"11\" name=\"kmanno\"></td></tr>";
			}
			
			echo"</table>";
			echo"<input type=\"submit\" value=\"Continua\">";
		}		//if per controllo campi vuoti
		else
		{	echo "$all_needed_set";
			$all_needed_set=1;}
		
	}		//parentesi if per controllo se all_needed_set=1;
	else
	{		//se settato a1lora continua
		session_register('ragsociale1' ,'ragsociale2', 'indirizzo', 'cap', 'citta', 'provincia', 'modauto',
	'targaauto', 'garanzia', 'circolare', 'telefono', 'cellulare', 'email', 'kmanno', 'dtnextcirc', 'dtproxcntr',
	'servizioneve', 'stampa_garanzia', 'stampa_circolare', 'sede');
		echo"<A HREF=\"anagrafica_ins1.php\">vai</a>";
	}
}
else  //altrimenti manda al modulo di form
{
		echo "Utente non verificato, effuare login <BR>";
        echo "<A HREF=\"auth_user.php\">Login</A><BR>";
}
?>
I don't know how to save in session the valued given in this file, I explain better, suppove user missed to insert 5 field, and for some unknown reason after he/she has been asked to insert he/she insert only 1, how do I tell php, he has inserted 1 field, save that one in php session's variables and display the new form with only the 4 missing??
I also tryied to pass $PHP_SELF as action of form but don't be able to insert session's variable at this point, please help me I'm getting stucked....Thanks
Paolo
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

My suggestion is that you validate the input for the 9 required fields.

Either use javascript or some php functions of your own. This would make your life easier for a start.
Post Reply