Search code examples
phpfat-free-framework

How to create server side validation in fat free framework?


how to check validate format for email and password and confirm password? how to return errors for required field.

here is my fat free function-

    $f3->route('GET|POST /addstep',
    function($f3) use ($db){
        $idss = $f3->get('SESSION.id');
        //print_r($_SESSION);die; 
        $data = json_decode($f3['BODY']);

        $title = $data->title;
        $first_name = $data->first_name;
        $middle_initial = $data->middle_initial;
        $last_name =  $data->last_name;
        $email = $data->email;
        $password = $data->password;
        $confirm_password = $data->confirm_password;
        $tax_id = $data->tax_id;
});

Solution

  • I created a little plugin that might be able to help you.

    Check the Fat Free Framework Validator

    Little example:

    $data = $f3->get('POST')
    $valid = Validate::is_valid($data, array(
        'username' => 'required|alpha_numeric',
        'password' => 'required|max_len,100|min_len,6'
    ));
    
    if($valid === true) {
        // continue
    } else {
        print_r($valid); // the invalid items
    }