Jump to content

error on form validation


funbinod

Recommended Posts

while trying another method for from validation i encountered error

	if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) {		unset($_SESSION['formAttempt']);		print "Error(s):<br />n";		foreach ($_SESSION['error'] as $error) {			print $error . "<br />n";		}	}

it returned error:

Warning: Invalid argument supplied for foreach() in E:xampphtdocsacpandavinstall.php on line 21

 

what could be this error! or it could be from action script!?

Link to comment
Share on other sites

following is the line from action script

if (isset($_SESSION['error'])) {	unset($_SESSION['error']);}$_SESSION['error'] = array();$required = array("company", "address", "user", "pass", "conpass");// check required fieldforeach ($required as $requiredField) {	if (!isset($_POST[$requiredField]) || $_POST[$requiredField] == "") {		$_SESSION['error'][] = $requiredField . "is required.";	}}
Link to comment
Share on other sites

In the if condition inside the foreach, instead of !isset(), try !empty(). isset doesn't really determine if there is a value or not. All it really means that a variable has been initiated. So for example, if you have:

 

<input type="text" name="username" />$_POST['username'] WILL be set even if it did not have a value entered (assigned) to it. (even if the user did not enter anything in the text box)Using empty() is more helpful in this situation because empty sees if there is anything that indicates a variable is empty, like an empty string '', or false, null, 0, etc.

Link to comment
Share on other sites

but what i faced the problem is not that. even after changing to !empty the problem remained same....

 

Warning: Invalid argument supplied for foreach() in E:xampphtdocsacpandavinstall.php on line 21

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...