Welcome Guest, Not a member yet? Register   Sign In
Validation tutorial
#1

(This post was last modified: 04-22-2020, 10:50 PM by Codinglander.)

Hi there, I'm back Wink

I have some Problems with the validation tutorial. I followed the steps for my own little project, but it doesn't work yet.
Here my code:

BaseController (part):
PHP Code:
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);

        
//--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        // $this->session = \Config\Services::session();

        $this->session = \Config\Services::session();
        $this->router = \Config\Services::router();
        $this->validation =  \Config\Services::validation();

        // Sample-data for the views
        $this->data = [
            'title'             => 'defaultTitle',
            'main_headline'     => 'Main Headline',
            'sitename'          => 'defaultSite',
            'menu_top'          => array(),
            'cur_controller'    => $this->router->controllerName(),
            'cur_method'        => $this->router->methodName(),
        ];


    } 

Controller with validation (part):
PHP Code:
public function sitesettings()
    {
        $this->validation->setRules([
            'site_admin_name'               => 'min_length[3]|max_lenght[250]',
            'site_admin_email'              => 'min_length[3]|max_length[250]|valid_email',
            'site_admin_pass_curr'          => 'required_without[site_admin_pass_new,site_admin_pass_new_retype]',
            'site_admin_pass_new'           => 'min_length[8]',
            'site_admin_pass_new_retype'    => 'matches[site_admin_pass_new]',
            'site_name'                     => 'max_length[200]',
            'site_description'              => 'min_length[3]',
            'site_keywords'                 => 'min_length[3]',
            'u_c_reason'                    => 'min_length[3]',
            'u_c_more_infos'                => 'min_length[3]'

        ]);
        if(! $this->validate([]))
        {
            $this->_set_active(4,1); // for my data['menu_top']
            $this->data['main_headline'] = 'Site Settings <small style="color: #6C757D; font-size: 40%">Use the input fields to change value. Keep them clear to change nothing.</small>';
            $this->data['validation'] = $this->validator;
            echo view('admin/sitesettings',$this->data);
        }
        else{
            $this->_set_alert('Speichern erfolgreich.','Die Site-Daten wurden erfolgreich übernommen');
            pre_output($_POST,true);
        }
    

The Form (part) :
Code:
<div class="col-sm-12">
    <?= $validation->listErrors() ?>
</div>
<form action="<?php echo base_url('admin/sitesettings') ?>" accept-charset="UTF-8" method="post">
    <?= csrf_field() ?>
    <div class="row" style="margin-bottom: 16px;">
        <div class="col-sm-12">
            <div class="card-deck">
                <div class="card">
                    <img src="https://dummyimage.com/490x123/a81ca8/2da337.png&text=+" class="card-img-top" alt="...">
                    <div class="card-img-overlay">
                        <h4><i class="fa fa-info-circle fa-fw"></i> Admin Infos</h4>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="form-group input input-group">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text"><i class="fa fa-user fa-fw"></i></span>
                                    </div>
                                    <span class="has-float-label">
                                        <input class="form-control" id="site_admin_name" name="site_admin_name" type="text" placeholder="Admin Name">
                                        <label for="site_admin_name">Admin Name</label>
                                    </span>
                                </div>
                                <div class="site_settings_helptext">
                                    <mark>Current:</mark> My Name
                                </div>
                            </div>

I set up the rules WITHOUT any "required" rule, so it should pass if only one field is filled up.
In the debugbar the $_POST array ist correctly filled out, but the form everytime is still reloaded instead of showing my success-screen.

Where is my issue ?!?
Reply


Messages In This Thread
Validation tutorial - by Codinglander - 04-22-2020, 10:48 PM
RE: Validation tutorial - by Leo - 04-23-2020, 02:51 AM
RE: Validation tutorial - by Codinglander - 04-23-2020, 03:17 AM
RE: Validation tutorial - by jreklund - 04-23-2020, 11:31 AM
RE: Validation tutorial - by Codinglander - 04-23-2020, 07:49 PM
RE: Validation tutorial - by jreklund - 04-24-2020, 09:40 AM
RE: Validation tutorial - by Codinglander - 04-24-2020, 11:12 AM
RE: Validation tutorial - by jreklund - 04-24-2020, 11:21 AM
RE: Validation tutorial - by hugoafr - 07-01-2020, 01:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB