Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1386 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Contact Form

Thread title: Contact Form
Closed Thread    
    Thread tools Search this thread Display Modes  
08-29-2007, 04:51 PM
#1
Haris is offline Haris
Status: Request a custom title
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 2,741
iTrader: 9 / 100%
 

Haris is on a distinguished road

  Old  Contact Form

Support is limited only for TFL members. I won't be reading your emails regarding support.

The contact form offers:
  • Clean commented code with meaningful variables.
  • Basic validation function to check email format. (Please request more validation rules)
  • Valid XHTML 1.0 Forms and Success Page
  • Support through TFL

Please don't bash if the code is not clean enough upto your standards or the code is not flexible enough. I cannot make everything perfect in one go, I'll be expanding and improving the code as I receive feedbacks.

Demo: http://www.mharis.net/contact_form/

Download: Updated on 29th August 2007

Attached Files
File Type: zip contact_form.zip (4.7 KB, 5 views)

08-29-2007, 06:19 PM
#2
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

some things I noticed on a quick glance
sendmail.php line #68, its best to include all files at the beginning, that way the programmer knows everything that is coming in at first glance.

You declare everything as global in functions, declaring it as global is only needed when you will access that specific variable outside of the function. Variables dont need to be declared, but if you want to you can just use the var keyword.

Lastly, its just good practice to use && and || instead of AND and OR


Otherwise a very nice and cleanly coded script, good work.

08-29-2007, 06:28 PM
#3
Haris is offline Haris
Status: Request a custom title
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 2,741
iTrader: 9 / 100%
 

Haris is on a distinguished road

  Old

Thanks Village.

I'll make sure to implement the changes in the next update.

EDIT: If I don't declare the variable, it comes up with strange "return" errors.

08-29-2007, 07:09 PM
#4
daz is offline daz
Status: I love this place
Join date: Jun 2005
Location: UK
Expertise:
Software:
 
Posts: 562
iTrader: 5 / 100%
 

daz is on a distinguished road

Send a message via MSN to daz

  Old

Good job Haris, but it's safer to use require_once or include_once rather than just include. And I don't really see the point in the validate_empty() function, just empty(code) should do.

08-29-2007, 07:18 PM
#5
Haris is offline Haris
Status: Request a custom title
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 2,741
iTrader: 9 / 100%
 

Haris is on a distinguished road

  Old

Originally Posted by daz View Post
Good job Haris, but it's safer to use require_once or include_once rather than just include. And I don't really see the point in the validate_empty() function, just empty(code) should do.
Spot on.

Thanks Daz.

08-30-2007, 12:25 AM
#6
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

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?

08-30-2007, 05:51 AM
#7
Haris is offline Haris
Status: Request a custom title
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 2,741
iTrader: 9 / 100%
 

Haris is on a distinguished road

  Old

I declared the keys from form_data array because the "return" function was generating errors for regex although now it doesn't. STRANGE!

$form_data was used to declare the globals. I wanted to make it easier for everyone to register the variables as global hence used form_data. Now there is no use so it's deleted.

I have improved the comments.

Thanks Salathe. If only there was a reputation system.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed