PHP help - required fields

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!

Moderator: General Moderators

Post Reply
dftho1
Forum Newbie
Posts: 1
Joined: Thu Jun 28, 2007 9:10 pm

PHP help - required fields

Post by dftho1 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi guys, I am completely new to PHP (novice is an understatement), so this question is pretty basic, sorry if it's been posted before, I had a look couldn't see anything.
Anyway basically all I want to do is make the $email_field required and need to be a valid e-mail address. I'm thinking this will only be an extra line or two so many thanks to anyone who can help out as PHP is quite foreign to me at the moment , cheers

Code: Select all

<?php
if(isset($_POST['submit'])) {

	$to = "whatever@hotmail.com"; 
	$subject = "Feedback Form";
	$name_field = $_POST['name']; 
	$email_field = $_POST['email']; 
	$message = $_POST['message']; 
  
	$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

	header( "Location: contact_thanks.html" );
	mail($to, $subject, $body);
	
} else {
	echo "_";
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Similar in principle to viewtopic.php?t=69814

Search my posts for "validateEmailFormat" for e-mail address validation (of the address itself, not if it exists.)
Post Reply