Welcome Guest, Not a member yet? Register   Sign In
Label in Form Validation

How do I put the name of the label in validation?
Not the field name.

in codeigniter 3 I did this
PHP Code:
$this->form_validation->set_rules('first_name','First Name','required'); 

how do i do this codeigniter n 4?
I'm trying this, but I can not.
PHP Code:
$validation->setRule('first_name','First Name','required'); 

This also does not work
PHP Code:
$validation->setRules(['first_name' => 'First Name''required']); 

CodeIgniter 4 Users Guide - Validation
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

I have not found anything in the documentation so that the name of the label can appear, not the field.

you can post an example of how I can do this?

If codeigniter 4 can not do this, I'm wasting time.
pois terei muito trabalho para criar uma menssagem personalizada para cada validação de cada campo de formulário.
Does anyone have a solution?

PHP Code:
public function email_agreement()
$messages = [
'notice_email' => [
'required' => 'Email is required',
'valid_email' => 'Email is invalid',
'notice_email' => 'required|valid_email',

        if (
$this->request->getPost('submitted') == null || 
$this->validation->withRequest($this->request)->run()) {
view('header', [
'current' => 'register'
'title' => 'Email Agreement'
'session' => $this->session,
view('email_agreement', [
'validation' => $this->validation
'session' => $this->session,
'confirm' => $this->request->getGet('confirm'),
        } else {
$confirm $this->request->getPost('confirm');
            if (
$confirm == 'yes')
Simpler is always better

I do not want it this way.
I do not want to use custom error message for each field.
This is very laborious if I have a large form.
I want to use codeigniter's own messages 4.
but I want the Label name to be displayed instead of the field name.
Field Name = first_name
Label Name = First Name (Display this)

(This post was last modified: 11-09-2017, 02:30 PM by donpwinston.)

Currently, I don't think you can. I'd like to do it that way too. It's less code.
Simpler is always better

Okay, I'm still waiting for more suggestions

Currently, no, it doesn't work like the old way. We are open to PR's though, to improve it. I'm slammed with work right now and am not getting much extra time to put into it for the next few weeks, likely.

At the very least, add an issue at GitHub. Though I don't see a really elegant way to handle it with the current system. Am open to suggestions on syntax that works with the current system and doesn't require an entire rework to match the old way just because we're comfortable with it. Smile

(This post was last modified: 11-15-2017, 07:09 PM by averroez.)

I think an alternative syntax to what we have would be more user friendly

PHP Code:
$validation->setRule('first_name''required', [
'label' => 'First Name',
'errors' => [ 'required' => 'The {attribute} field is required.' ]
// or single rule per call like so, bit more verbose
'message' => 'The first name is required.' 

Theme © iAndrew 2016 - Forum software by © MyBB