Operating with form data

After form data validation, we can now extract field values for further use.

//Value of specified field 
$form -> getValue("staff");

//Another way to get a field value
$form -> staff;

//Value (name) of "enum" type field (not a key)
$form -> getEnumTitle("gender");

//All form values, returns an associative array 
$form -> getAllValues();

/Selected form values, returns an associative array
$form -> getAllValues(array("company", "about", "staff"));

//Pass form values into model object 
$data = $form -> getAllValues(array("company", "type", "email"));
$mv -> clients -> getDataFromArray($data);
$mv -> clients -> create();

//Pass form values into object of Record class to create/update a record 
$values = $form -> getAllValues(array("first_name", "last_name", "email"));
$client = $mv -> clients -> findRecordById(34);
$client -> setValues($values) -> update();

//Create a list of all fields to send e-mail
$message = $form -> composeMessage();

//Create a  list of selected fields in a required sequence to send e-mail 
$message = $form -> composeMessage(array("company", "about", "email"));

Let's assume we have an URL "/question /", by which the contact form should open. We'll call the tempalte file as "view-contact.php" and we will specify in "config/routes.php" file the line "question/" => "view-contact.php". Also we will create in the module of pages the new page with the field "Link" that has "question" value.

Below is the content of "views/view-contact.php" file.

$content = $mv -> pages -> findRecord(array("url" => "question", "active" => 1));
$mv -> display404($content);
$fields = array(
    array("Имя", "char", "name", array("required" => true)),
    array("Email", "email", "email", array("required" => true)),
    array("Message", "text", "message", array("required" => true)),
    array("Security code", "char", "captcha", array("required" => true,
                                                    "captcha" => "extra/captcha-code/")));
$form = new Form($fields);
    $form -> getDataFromPost() -> validate();

    if($form -> getValue("captcha"))
        if(!isset($_SESSION["captcha"]) || $_SESSION["captcha"] != $form -> getValue("captcha"))
            $form -> addError("Wrong security code.");
    if($form -> isValid())
        $message = $form -> composeMessage(array("name", "email", "message"));
        $message .= $mv -> registry -> getSetting("EmailSigature");

        Email :: send($mv -> options -> admin_email, "Question from a website", $message);
        $mv -> reload("?sent");

include $mv -> views_path."main-header.php";
<div id="content">
    <div id="page" class="editable">   
        <h1><? echo $content -> name; ?></h1>
            echo $form -> displayErrors();
                echo "<p>Your message was successfully sent.</p>";
                echo $content -> content;
                $fields = array("name", "email", "message", "captcha");

                //We put the form code into separated file and include it if needed
                include $mv -> views_path."parts/form-typical.php";
include $mv -> views_path."main-footer.php";