TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-16-2008, 02:55 PM   #1 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default Required fields in a contact form

I am making a contact form that needs required fields. I have it set for one field to be required, but when I try to make the other fields required I get a white page. Here is my code:
Code:
if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];
  $to = "something@somewhere.com";
  if(!$name && !$email && !$message) {
    $error = '<p style="color:#FF0000">Please complete all required fields</p>';
  } else {
	$subject = "TxDOT Watch Report";
	$from = "From: $email \r \n";
	
    ini_set('sendmail_from', $email);
	mail($to, $subject, $from, $message);
  }
}
Any help will be appreciated. Thanks
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 12-16-2008, 03:00 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

You are using and commands in your if statement, thus it will not trigger unless all of them are empty. The blank screen is the script sending the mail.
__________________

Village Idiot is offline  
Reply With Quote
Old 12-16-2008, 03:02 PM   #3 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
You are using and commands in your if statement, thus it will not trigger unless all of them are empty. The blank screen is the script sending the mail.
The mailing script is on the same page as the html form. How do I make it work?
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 12-16-2008, 03:16 PM   #4 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default

Ok I got the fields to be required by changing
Code:
if(!$name && !$email && !$message) {
To
Code:
if(empty($name) || empty($email) || empty($message)) {
Now, how would I set ti so the user does not have to enter the data in again and just fill in the empty fields?
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 12-16-2008, 03:34 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

There are a few ways, ajax could return an error message so the fields don't go blank, you could have the script post to itself so that you can fill the form with the posted data. Those are what I can think of off hand.
__________________

Village Idiot is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Contact Form Script Matt83 Script Giveaway 20 10-22-2012 10:18 AM
PHP Contact Form - 2 Questions ncmason General 0 05-26-2008 02:38 AM
Contact Us Form Mohamad Script Giveaway 4 10-03-2007 02:22 PM
Simple & Expansive Contact Form Wildhoney Script Giveaway 4 09-11-2007 03:04 PM
Form Processing William Tips & Tricks 8 04-17-2005 03:24 PM


All times are GMT. The time now is 03:57 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design