Good to see some coders throwing out some code snippets.
I know that you said, "
Please don't bash if the code is not clean enough upto your standards or the code is not flexible enough." However I'm going to provide a little feedback anyway and hope that you don't see my comments as bashing.
Validation Functions
Maybe it's just my tired, overworked brain (it's late) but why do you go through the process of (for want of a better word) 'globalising' the
$form_data keys at all?
For
validate_empty() maybe it was your intention but PHP's
empty() function returns true for more than just empty strings. Perhaps you could use
strlen() instead? Unless you want to flag things like "0" as empty.
For
validate_email() I'd recommend using
preg_match() rather than
eregi(). The former is around 2-2.5 times faster (rough figure). The pattern is the same, just wrap it in delimiters and add the
i modifier.
Comments
Most of the comments do not very much more than act as delimiters to different sections of the script. Maybe you'd like to make them a little more useful by including more information. I'll pick out a few that particularly jump out at me.
mail(_) used to send email - This is used above the block of code which deals with validating the form data and sending the email (or not) depending on whether the validation tests are passed. The comment instead just states the obvious, that the mail function sends an email.
Validates empty fields - This is for the
validate_empty function. You don't say whether the function returns true when the field is empty, or false. The comment and function name combined do not make it clear whether an empty (string) field would be considered as valid or invalid. Perhaps change the function name to
validate_not_empty?
Finally, what's the point of
$form_data?