MV framework logo
  • Architecture
    • Philosophy
    • Technologies
  • Admin Panel
  • Changelog
  • Support
  • Feedback
Download Version 2.6 from 07.10.2022
Documentation
  • Architecture
    • Philosophy
    • Technologies
  • Admin Panel
  • Changelog
  • Support
  • Feedback
Getting started
  • Installation and launch
  • System folders
  • Launch of simple website
  • Pre-installed models
  • System settings
Models
  • General principles of models
  • Data types
  • Model settings
  • Simple models
  • Foreign keys
  • Trees
  • Many to many
  • Group
  • Records management
  • Simple model management
  • Additional options
Views and routes
  • General principles of views
  • Router object
  • MV object
  • Index, default and 404 templates
  • Creating a new template
  • Data display in template
  • Object of Record class
  • Files and images
  • Date and time
  • Redirects
  • Email delivery
  • Special methods
Forms
  • Forms creation
  • Form fields settings
  • Form validation rules
  • Form validation process
  • Operations with form data
  • Using data from models
  • Form methods
SQL queries
  • Query constructor
  • Direct queries
  • Pagination
  • Sorting
  • Filtration
  • Upload from CSV files
Sessions and security
  • Work with sessions
  • AJAX
  • Security
  • Debugging
Plugins
  • General principles of plugins
  • Additions to admin panel
  • Caching
Documentation
Getting started
  • Installation and launch
  • System folders
  • Launch of simple website
  • Pre-installed models
  • System settings
Models
  • General principles of models
  • Data types
  • Model settings
  • Simple models
  • Foreign keys
  • Trees
  • Many to many
  • Group
  • Records management
  • Simple model management
  • Additional options
Views and routes
  • General principles of views
  • Router object
  • MV object
  • Index, default and 404 templates
  • Creating a new template
  • Data display in template
  • Object of Record class
  • Files and images
  • Date and time
  • Redirects
  • Email delivery
  • Special methods
Forms
  • Forms creation
  • Form fields settings
  • Form validation rules
  • Form validation process
  • Operations with form data
  • Using data from models
  • Form methods
SQL queries
  • Query constructor
  • Direct queries
  • Pagination
  • Sorting
  • Filtration
  • Upload from CSV files
Sessions and security
  • Work with sessions
  • AJAX
  • Security
  • Debugging
Plugins
  • General principles of plugins
  • Additions to admin panel
  • Caching

Operations with form data

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

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

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

//Value (title, 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 certain 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 be opened. We will call the template file as "view-contact.php" and 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);
 
if(!empty($_POST))
{
    $form -> getDataFromPost() -> validate();

    if($form -> captcha)
        if(!isset($_SESSION["captcha"]) || $_SESSION["captcha"] != $form -> captcha)
            $form -> addError("Wrong security code.");
 
    if($form -> isValid())
    {
        $message = $form -> composeMessage(array("name", "email", "message"));
        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();
 
            if(isset($_GET['sent']))
                echo "<p>Your message was successfully sent.</p>";
            else
            {
                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";
            } 
        ?>
    </div>      
</div>
 
<?
include $mv -> views_path."main-footer.php";
?>

To use CAPTCHA we also need to switch on session use in config file.

Previous section

Form validation process

Next section

Using data from models

© 2012-2023, MV framework

MV tracker is based on open source MV framework
License