Welcome Guest, Not a member yet? Register   Sign In
How to validate field with brackets in name
#1

(This post was last modified: 09-07-2022, 03:13 AM by groovebird.)

Hi,

i have 3 radio buttons with the following name:

radio name="button[10]" value="15"
radio name="button[10]" value="16"
radio name="button[10]" value="17"

This is the rule:

PHP Code:
$rules = [
  
'button[10]' => [
    
'label' => '',
    
'rules' => 'required',
    
'errors' => [
      
'required' => 'Please check the radio button'
    
]
  ]
]; 

If i check one radiobutton the error message is still displayed. what i am doing wrong?
Reply
#2

Did you assign a value to each radio button?
Reply
#3

(09-07-2022, 02:52 AM)JustJohnQ Wrote: Did you assign a value to each radio button?

yes, every radio button has its own value
Reply
#4

(This post was last modified: 09-07-2022, 03:59 AM by JustJohnQ.)

Try changing button[10] in rules to button.*
Reply
#5

(09-07-2022, 03:33 AM)JustJohnQ Wrote: Try changing button[10] in rules to button.*

Thank you :-), this seems to work, but i have groups of buttons with the name

name="button[20]" and name="button[30]"

How can i validate this different fields individually?
Every radio button group should have it's own error message. With button.* all fields will be affected.
Reply
#6

(This post was last modified: 09-07-2022, 03:59 AM by JustJohnQ. Edit Reason: added link to documentation )

button.10 etc....

http://codeigniter.com/user_guide/librar...are-arrays
Reply
#7

(09-07-2022, 03:55 AM)JustJohnQ Wrote: button.10 etc....

http://codeigniter.com/user_guide/librar...are-arrays

I tried this but it was not working because of a typo Sad Found the dot notation in the documentation. Now it is working.

Thank you very much for your help
Reply
#8

(This post was last modified: 09-07-2022, 11:07 PM by Ahmed Haroon.)

@groovebird
will you please help us ' what was and where was ' that " typo " (the dot notation) and how you resolve this problem? so, the juniors should be aware of it.
thanks in advance.
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply
#9

@Ahmed Haroon i used the dot notation but misspelled the name of the input field in the showError() function. This was the reason why no error message was displayed

$validation->showError('button.10') shows me the correct error message
Reply
#10

(09-08-2022, 01:22 AM)groovebird Wrote: @Ahmed Haroon i used the dot notation but misspelled the name of the input field in the showError() function. This was the reason why no error message was displayed

$validation->showError('button.10') shows me the correct error message

thanks for your feedback, this will help us for sure.
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB