Jump to content

help with giving error codes on form submission


shane85

Recommended Posts

hey guys. Right now upon form submission, I do an error check that puts all the errors into an array, then will display them at the top of the form. What I want to do though is break up the array, and be able to give each error msg in its indivdual table row in the html. Right now, my coding is

	if($lname == '') {
	$errmsg_arr[] = 'You must enter your last name';
	$errflag = true;
}
if($email == '') {
	$errmsg_arr[] = 'You must enter your email address';
	$errflag = true;
}
if($city == '') {
	$errmsg_arr[] = 'You must enter your city';
	$errflag = true;
}

if($errflag) {
	$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
	session_write_close();
	header("location: signup_artist.php");
	exit();
}

 

thats in form2.php

 

form 1.php has the following snipet of code

 

<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
	echo '<ul class="err">';
	foreach($_SESSION['ERRMSG_ARR'] as $msg) {
		echo '<li>',$msg,'</li>'; 
	}
	echo '</ul>';
	unset($_SESSION['ERRMSG_ARR']);
}
?>

 

so basically would I would like to be able to do is identify each error as for instane $fname_error $lname_error etc and then load them into my html appropriately, as opposed to just an array listing them

You would basically do this exactly how you are currently.

 

If you want the error message to show up next to the fname box you'd just do a simple if statement to display that...  but to do that, you'd need to change your if statements above as well that generate the errors.

 

if ($_SESSION['ERRMSG_ARR']['f_name'] != '') { echo $_SESSION['ERRMSG_ARR']['f_name']; }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.