WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Check empty fields
Categories : PHP, HTML and PHP, Form Processing Click here to Update Your Picture
Olaf Lederer
Date : Mar 24th 2005
Grade : 2 of 5 (graded 4 times)
Viewed : 20141
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Olaf Lederer
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
/*
Almost for every submitted form you need a simple form check about the required fields. The validation and reporting will become very hard to handle if you have more then three required fields. This function will do all this work: Validation of required fields and the error reporting. After submitting you get a message which fields are empty and the empty fields are in a different colour. The example will handle only the text type input elements.
*/

// use associative array's if you like
$req_fields = array("name", "timestamp"=>"Your time", "field");
$msg = "The following (required) fields are empty:";

function
check_empty_fields($method = "post") {
    global
$req_fields, $msg;
   
$invalid = false;
   
$data_array = ($method == "post") ? $_POST : $_GET;
   
$errors = "";
   
$count_empty = 0;
    foreach (
$data_array as $key => $val) {
       
$field_name = (array_key_exists($key, $req_fields)) ?  $req_fields[$key] : $key;
        if (
in_array($field_name, $req_fields) &&    $val == "") {
           
$GLOBALS[$field_name] = false;
           
$errors .= "|".$field_name;
           
$count_empty++;
        }
    }
    if (
$count_empty == 0) {
       
$msg = " ";
        return
true;
    } else {
       
$msg_parts = explode("|", ltrim($errors, "|"));
       
$num_parts = count($msg_parts);
       
$msg .= "<br>";
        for (
$i = 0; $i < $num_parts; $i++) {
           
$msg .= $msg_parts[$i];
            if (
$i <= $num_parts - 2) {
               
$msg .= ($i == $num_parts - 2) ? " & " : ", ";
            }
        }
        return
false;
    }
}
?>


example (check the demo page for a result)
<?php
if (isset($_POST)) check_empty_fields();
// and the form field like:
// echo <input type=\"text" name=\"name\"";
// if (isset($_POST['name'])) echo " value=\"".$_POST['name']."\"";
// if (!$GLOBALS['name']) echo " class=\"invalid\">";
?>



The Nearly Perfect Contact Us Form
Categories : PHP, Form Processing, HTML and PHP
Simple PHP Form Field Generator
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
Dynamic form field
Categories : PHP, HTML and PHP, Form Processing
Sql Builder
Categories : PHP, HTML and PHP, Databases, General SQL, Form Processing
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
Pseudo Non Parsed Header. Output to the the browser as the script runs.
Categories : PHP, HTTP, HTML and PHP
PageRank Display
Categories : Search Engines, HTML and PHP, PHP
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP
XTemplate, a template class for PHP
Categories : PHP Classes, HTML and PHP, PHP
Upload Script, Upload File Script, Input Type="File"
Categories : PHP, HTML and PHP, HTTP
Opening and formatting text files into HTML on the fly- or HTML from templates.
Categories : PHP, HTML and PHP, Filesystem
This script shows you the 7th latest php items from the mailing list archive on zend.com
Categories : HTML, HTML and PHP, HTTP, PHP
AITSH Statistics
Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP