Welcome Guest, Not a member yet? Register   Sign In
Form validation: error message
#1

(This post was last modified: 09-22-2018, 04:49 AM by Serializable.)

Base URL for registration page:
Code:
http://localhost/codeigniter-project/users/register

Registration page:
PHP Code:
<?php echo validation_errors('<p class="bg-danger">'); ?>
<?php 
echo form_open('users/register', ['id' => 'register_form''class' => 'form-horizontal']); ?>
    <div class="form-group">
        <?php
        
echo form_label('First name');
        echo form_input([
            'name' => 'first_name',
            'value' => set_value('first_name'),
            'class' => 'form-control',
            'placeholder' => 'Enter first name',
        ]);
        ?>
    </div>

    ... 

Controller:
PHP Code:
class Users extends CI_Controller
{
    public function register()
    {
        $this->form_validation->set_rules('first_name''First name''trim|required|min_length[2]');
        $this->form_validation->set_rules('last_name''Last name''trim|required|min_length[2]');

        if ($this->form_validation->run() == false) {
            return $this->load->view('layouts/main', ['main_view' => 'users/register']);
        }

        ... 

When I open the URL for the very first time there were no validation errors produced.
But if I try to fill the form and for example provide only 'fisrt name' (and do not provide 'last name'), then validation errors generated and displayed on the register page.
So why were no errors genererated in the beginning, when I open the base url for the very first time?
Reply


Messages In This Thread
Form validation: error message - by Serializable - 09-22-2018, 03:40 AM
RE: Form validation: error message - by jreklund - 09-22-2018, 04:14 AM
RE: Form validation: error message - by Wouter60 - 09-22-2018, 10:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB