|
|
|
|
|
|
| |
| <?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\">";
?> | | |
|
| Simple PHP Form Field Generator Categories : PHP, Beginner Guides, Form Processing, HTML and PHP | | | Sql Builder Categories : PHP, HTML and PHP, Databases, General SQL, Form Processing | | | Dynamic form field Categories : PHP, HTML and PHP, 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 | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | |
|
|
|