[SLUG] Re: slug] Required fields in PHP

From: R P Herrold (herrold@owlriver.com)
Date: Wed Feb 18 2004 - 22:10:13 EST


On Wed, 18 Feb 2004, Paul M Foster wrote:

> When coding forms in PHP, is there a _simple_ way to ensure certain
> required fields are actually filled out?

javascript onexit's can test for non-null field contents;
without javascript, at the top of the POST or GET, you can add
this kind of test before processing:

<?php
//... stuff
$var = $_POST[var];
// ... detaint against hostile content omitted
if ("$var" == "") {
        print "Error: var cannot be empty <br>";
        $retry = "y";
        }
// ... stuff omitted
//
// and then test for an error before dispatching to a
// processor
if ("$retry" == "") {
        header("Location: http://www.domain.com/handle_post.php");
        } else {
        print "Some errors were noted, as above -- let's retry <br>";
        }

-- Russ Herrold
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:59:42 EDT