如何在php中成功验证后获取数据


how to get data after successful validation in php

嗨,我正在处理我的表单和验证过程,到目前为止还不错我有一个php脚本,可以根据我的需要验证我的字段,但我是php的新手,不知道我应该在哪里编写这一部分

    if( isset($_POST['name']) )
    {
        $to = 'myemail@gmail.com'; 
        $subject = 'NEWLOGO CLIENT FORM'; 
        $headers = 'From: ' . $_POST['email'] . "'r'n" . 'Reply-To: ' . $_POST['email'];
$message = 'Name: ' . $_POST['name'] . "'n" .
               'Surname: ' . $_POST['surname'] . "'n" .
               'E-mail: ' . $_POST['email'] . "'n" .
               'Phone: ' . $_POST['phone']. "'n" .

在这个里面

<?php
require_once('validator.php');
if(isset($_POST['form_btn'])) {
    $validator = new simple_fv;
    $fields = array();
    $fields[] = array('index'=>'name', 'label'=>'Name', 'required'=>true, 'max_len'=>25);
    $fields[] = array('index'=>'surname', 'label'=>'surname', 'required'=>true, 'max_len'=>30);
    $fields[] = array('index'=>'slider1-value', 'label'=>'Simple vs Complex');
    $fields[] = array('index'=>'slider2-value', 'label'=>'Young vs Mature');
    $fields[] = array('index'=>'slider3-value', 'label'=>'Luxury vs Economical');
    $fields[] = array('index'=>'slider4-value', 'label'=>'Modern vs Classic');
     $fields[] = array('index'=>'slider5-value', 'label'=>'Luxury vs Economical');

    // validate the fields
    $validator->formHandle($fields);
    // get errors
    $error = $validator->getErrors();
    // if errors is not FALSE - print the succesfull message
    if($error) {echo $error;}
    else {echo 'SUCCESFULL MESSAGE'; }  
}
?>

这只是我表格的一部分。每次尝试时,它都会向我发送数据,而不在php中进行验证。以及可能如何在CCD_ 1之后将用户带回提前感谢

使用form_val获取值

<?php
require_once('validator.php');
if(isset($_POST['form_btn'])) {
    $validator = new simple_fv;
    $fields = array();
    $fields[] = array('index'=>'name', 'label'=>'Name', 'required'=>true, 'max_len'=>25);
    $fields[] = array('index'=>'surname', 'label'=>'surname', 'required'=>true, 'max_len'=>30);
    $fields[] = array('index'=>'slider1-value', 'label'=>'Simple vs Complex');
    $fields[] = array('index'=>'slider2-value', 'label'=>'Young vs Mature');
    $fields[] = array('index'=>'slider3-value', 'label'=>'Luxury vs Economical');
    $fields[] = array('index'=>'slider4-value', 'label'=>'Modern vs Classic');
    $fields[] = array('index'=>'slider5-value', 'label'=>'Luxury vs Economical');

    // validate the fields
    $validator->formHandle($fields);
    // get errors
    $error = $validator->getErrors();
    // if errors is not FALSE - print the succesfull message
    if($error) {
        echo $error;
    }else {
        echo 'SUCCESFULL VALIDATION!'; 
        //send mail
        $fdata = $validator->form_val;
        $to = 'myemail@gmail.com'; 
        $subject = 'NEWLOGO CLIENT FORM'; 
        $headers = 'From: ' . $fdata['email'] . "'r'n" . 'Reply-To: ' . $fdata['email'];
        $message = 'Name: ' . $fdata['name'] . "'n" .
                   'Surname: ' . $fdata['surname'] . "'n" .
                   'E-mail: ' . $fdata['email'] . "'n" .
                   'Phone: ' . $fdata['phone']. "'n" .
        //.............
        if(mail($to, $subject, $message, $headers){
            echo 'SUCCESFULL VALIDATION';
        }else{
            echo 'FAILED TO SEND';
        }
    }  
}
?>