PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 15th, 2005, 11:42 PM
gdogfunk gdogfunk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 gdogfunk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 18 sec
Reputation Power: 0
PHP form verification?

Hello,

I have created a guestbook in PHP from scratch since the CGI version included with my web hosting package sucks. Everything works great, except that lately, people have been pressing the submit button without entering text in the text fields, thus emailing me a link to the page and there lies a blank entry. I'm getting tired of deleting the blanks and it dawned on me that there might be a way to require at least one field to have text or it won't popluate the database, but I don't have a clue how to do it. I have all of the fields NULL (except for the entry_ID), but I don't want the user to have to fill out every field either.

Can anyone tell me how to verify that at least one field has text or no submission?

Any help would be greatly appreciated!

Thanks!

Ryan

Reply With Quote
  #2  
Old February 16th, 2005, 08:45 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Ryan,

Lets us assume the field you wish to verify has a name of 'message'. In your PHP code you want to do the following:

PHP Code:
 $message '';
 if ( (isset(
$_POST['message'])) && (!empty($_POST['message'])) ) $message $_POST['message'];
 if ( (isset(
$_GET['message'])) && (!empty($_GET['message'])) ) $message $_GET['message'];

$if (''==$message) exit('You must enter a message first...'); 

In english, the above code says, If message is in the POST headers, add it to the $message variable, but if it is in the GET message do the same. If both were available, GET would override POST.

If neither exist or is blank code execution stops.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP form verification?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT