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

Link to comment
Share on other sites

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']; }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.