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!
There were a few problems which was causing it not to work.
Your form contained no field named "submit" when you were checking for it on line 6
Line 6 was updated to: if(!isset($_POST ['submit']))
Line 31 was updated to: <input name="submit" type="submit" id="add" value="Submit">
Another point, you were using if statements without formatted statements inside. If you use a non { } if statement, tab it
Each if statement was reflected to include { }
Rather than check if the error string == "", i replace with empty() which covers all forms of 'nothing' - empty() function
angelicodin wrote:I've been wanting a function like this and didn't even knew it existed
You mean the form validation script?
When you think about it, it can be rather inefficient using a string to hold your errors. Especially if you have more than a single error.
I have been working on an Error class of my own which is supposed to handle errors quite easily.
Example:
# Set an error to the specified field.
$error->setFieldError("username",ERROR_USER); // where ERROR_USER is a defined numerical value
// The numerical value CURRENTLY relates to a specified array of known errors.
// For instance, my ERROR_USER is defined as 2, which in the error array located in the error class is:
// $errorArray[2] = "Error: Username"
# Output error if an error for the field exists
if($error->value("username")){
print $error->printError("username");
}
If you'd like, PM me and i can send you a copy of the code i currently have. You would probably need the database class as well for it to work properly.