Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 31st Aug 2010, 11:33 AM   #1
Active Warrior
 
topfree's Avatar
 
Join Date: 2010
Posts: 80
Thanks: 3
Thanked 3 Times in 3 Posts
Default
How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

I need some kind of validation to make sure the fields contain date, I get a lot of blank emails. Any ideas on how to do that with this form?


<form action="step2.php" method="post">

Name<br/><input type="text" value="" name="username"/> <br/>

Email<br/><input type="text" value="" name="email"/> <br/>

Inquiry<br/><textarea row="7" cols="30" name="inquiry"></textarea><br/>

<input type="submit" value="send your email" name "submit">

</form>

Free E-booklet
Make At Least $500 Dollars Your First Month On Adsense

Get 1 year hosting for $50
Click Here
topfree is offline  
Unread 31st Aug 2010, 01:01 PM   #2
HyperActive Warrior
War Room Member
 
Join Date: 2009
Location: Vancouver, British Columbia, Canada
Posts: 114
Thanks: 9
Thanked 8 Times in 7 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

If you're familiar with PHP, do some validation in 'step2.php'. Here's a very simple example:

$userName = $_POST['username'];
$email = $_POST['email'];

if((trim($userName) == ""))) {
echo "You must enter a username.";
}
elseif((trim($email) == ""))) {
echo "You must enter an email address.";
//I would actually check for a valid email address
}

If you're not familiar with PHP, use a CAPTCHA if you're receiving spam inquiries.
The Official CAPTCHA Site

Services like Wufoo or Machform (a self-hosted form creator) allow you to create forms easily with validation options you can select.
Wufoo: Wufoo: Online Form Builder - Create Web Forms & Surveys
Machform: MachForm - PHP HTML Form Builder - Mailer Form Creator
cmaclean is offline  
Unread 31st Aug 2010, 01:21 PM   #3
Active Warrior
 
topfree's Avatar
 
Join Date: 2010
Posts: 80
Thanks: 3
Thanked 3 Times in 3 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

Originally Posted by cmaclean View Post

If you're familiar with PHP, do some validation in 'step2.php'. Here's a very simple example:
Here is my current php setup, how should I add that code to it?

<?php

$name = $_POST['username'];
$email = $_POST['email'];
$text = $_POST['inquiry'];

//To, Subject, Message, Header
mail('myemail@somewhere.com', 'Inquiry', $text, 'From: ' . $name . ' <' . $email . '>');

header('location: step3');
?>

Free E-booklet
Make At Least $500 Dollars Your First Month On Adsense

Get 1 year hosting for $50
Click Here
topfree is offline  
Unread 31st Aug 2010, 07:50 PM   #4
Warrior Member
War Room Member
 
Join Date: 2010
Location: Bryan, TX
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

Here is a nice example of a javascript validation script.

JavaScript Form Validation
HONUware is offline  
Unread 31st Aug 2010, 08:24 PM   #5
Active Warrior
War Room Member
 
bucksuper's Avatar
 
Join Date: 2008
Location: Seattle, WA
Posts: 35
Thanks: 3
Thanked 5 Times in 5 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

Hello,
I've used this form validator on quite a few projects. All the instructions are on the following page and it's super easy to use. JavaScript Form Validation : quick and easy!

If you need any assistance getting it going feel free to get in touch with me.
Best of luck!

300% Traffic Return check out Trippy Wire Content Exchange! (100% FREE!)
Trippy Wire Content Exchage Network

Trippy Wire is looking for partners in these niches niches: Humor, Movies, Gaming, Celebrities, Entertainment, Sports, Food & Drinks, Hot Women, Technology & Transportation.
bucksuper is offline  
Unread 2nd Sep 2010, 01:57 AM   #6
Active Warrior
 
Join Date: 2010
Posts: 61
Thanks: 2
Thanked 6 Times in 5 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

I have used this really good looking form validation, it looks really cool.

http://tetlaw.id.au/view/javascript/...eld-validation

HostCP - cPanel iPhone app to manage your cPanel accounts using cPanel's official API
WordpressInstaller.net - Automatically install & configure Wordpress Blog, Theme, Plugins and Posts. Wordpress Installer will DO IT ALL for you in just a FEW SECONDS AND best of all, it's FREE
Mihir.info - A developer's blog
mihir is offline  
Unread 3rd Sep 2010, 05:10 AM   #7
Warrior Member
 
Join Date: 2009
Posts: 21
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

THANKS FOR SHARING INFORMATION

sbglobal123 is offline  
Unread 4th Sep 2010, 12:34 PM   #8
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

Just a quick note: do NOT depend on javascript validation. Yes, most users haven't turned off javascript in their browsers - but the bad guys do.

I could use your email form to broadcast thousands of emails and you wouldn't even know it until your hosting company shut you down.

Google 'php email injection'; you'll get some ideas of how to sanitize your form data before sending it.

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
Unread 4th Sep 2010, 12:44 PM   #9
Active Warrior
 
Join Date: 2010
Posts: 88
Thanks: 1
Thanked 3 Times in 3 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

Must use JQuery validation its great.
zeeshi570 is offline  
Unread 4th Sep 2010, 01:06 PM   #10
Night Angel
 
hhunt's Avatar
 
Join Date: 2009
Location: Underground
Posts: 158
Thanks: 2
Thanked 14 Times in 14 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

Originally Posted by sbglobal123 View Post

THANKS FOR SHARING INFORMATION
Pay attention to CAPS LOCK - they are frowned upon.

That said, whatever validation you do on client-side, it is a good practice to also validate on the server-side. Scammers will always inject data into your 'step2.php', so make sure you validate it, otherwise you will continue getting blanks and garbage emails.

Just a thought!

hhunt is offline  
Unread 12th Sep 2010, 02:21 AM   #11
Warrior Member
War Room Member
 
Dagobert's Avatar
 
Join Date: 2010
Location: Cambodia
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

U can try regex.
in javascript:
/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test("email address");
return true or false.

Dagobert is offline  
Unread 15th Sep 2010, 08:01 PM   #12
Active Warrior
 
Join Date: 2010
Location: Phoenix, AZ
Posts: 37
Thanks: 2
Thanked 6 Times in 5 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

I modified the code you pasted for step2.php, here is a modified version that will validate your form:

<?php

$name = $_POST['username'];
$email = $_POST['email'];
$text = $_POST['inquiry'];

//*****Switch to decide whether to show error or move on.
$validation_switch = "ON";

//*****Change this value to a custom error message alert.
$errormessage = "Error\n";

if((trim($username) == ""))) {
validation_switch = "OFF";
$errormessage.= "You must enter a user name.\n";
}

if((trim($email) == ""))) {
validation_switch = "OFF";
$errormessage.= "You must enter a valid email.\n";
}

if((trim($text) == ""))) {
validation_switch = "OFF";
$errormessage.= "Please remember to enter your inquiry.\n";
}

if($validation_switch == "ON"){

//To, Subject, Message, Header
mail('myemail@somewhere.com', 'Inquiry', $text, 'From: ' . $name . ' <' . $email . '>');

header('location: step3');
}

if($validation_switch == "OFF"){
echo "$errormessage";
}

?>

I could have used an elseif there, but this makes it more clear.
lknielsen is offline  
Unread 15th Sep 2010, 11:15 PM   #13
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

Sorry, but that's not any kind of validation worth mentioning. It just checks to see if a form field is empty. That's not nearly good enough.

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
Unread 16th Sep 2010, 01:39 AM   #14
Web Developer
 
Join Date: 2010
Location: Wisconsin
Posts: 322
Thanks: 2
Thanked 80 Times in 74 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

SteveJohnson is correct..
None of these examples actually validates anything.

You need to first strip out any code the user may have entered in any of the fields.
Then see if the fields are empty, if not --

Check that the email address is valid using an array of different expression patterns.

Then make sure that it was actually submitted eg. testing for the following --

Make sure that it was submitted from your actual script and not hijacked via cURL or other functions and used to spam every email on the internet.

And I am just winging it, probably missed a check or 2.

All of these checks need to be done with a server side language eg. PHP

A really good captcha should be used also unless you want a 1000 bot submissions.

JavaScript validation is for pretty checks to notify the user they messed up.
Its not validation by any means.


If you can't pull off all of these true validations, I suggest hiring someone that can code it properly and secure.

phpbbxpert is offline  
Unread 1st Oct 2010, 11:50 PM   #15
Warrior Member
 
Join Date: 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: How should I validate this email form?
Share on: 
fb share twitter share gplus share more share

It is difficult to know what of validation that actually is, it is only to know whether a form field is empty or not.

ryanhall789 is offline  
Closed Thread


Bookmarks

Tags
email, form, validate


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 12:44 AM.