set_from_form($array)

if $array is not an array: return false

Attempts to set class variables with names coinciding with the array indexes and values coinciding with their respective values.

will not set (or change) the primary key column of the table

If the "database column" variable is not set, it will be set as not set. For boolean values, an unset variable defaults to false (for checkboxes)

The value must meet the variable setter validation requirements. The function will create an array of variable names that fail to meet the requirements. If this array exists (there are errors), return $error_array

If there were no issues return null

function code:
<?php
    
function set_from_form($array '')
    {
        
$errors null;
        if (@!
is_array($array))
            return 
false;
        foreach(
$this->_columns as $column=>$column_info)
        {
            if (
$column == $this->_primary_key_column)
                continue;
            if (@!
$this->{"set_$column"}($array[$column]))
                
$errors[] = $this->{$column."_label"};
        }
        return 
$errors;
    }
?>



Example:

example.php
<?php
include("lib.php");
load("person");

if (
$array $_POST["array"])
{
    
$p = new person;
    if (
$errors $p->set_from_form($array))
    {
        echo 
"Error. The following fields are invalid: ";
        echo 
implode(", "$errors);
        echo 
".";
        return 
0;
    }
    else
    {
        ...
    }
}

?>


<form method=post action=example.php>
Name:<input type=text name=array[name]><br>
Address:<input type=text name=array[address]><br>
City:<input type=text name=array[city]><br>
State:<input type=text name=array[state]><br>
Age:<input type=text name=array[age]><br>
Birthdate:<input type=text name=array[birthdate]><br>
<input type=submit value=Submit>
</form>