CodeIgniter Forums
How to validate field with brackets in name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to validate field with brackets in name (/showthread.php?tid=82985)



How to validate field with brackets in name - groovebird - 09-07-2022

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?


RE: How to validate field with brackets in name - JustJohnQ - 09-07-2022

Did you assign a value to each radio button?


RE: How to validate field with brackets in name - groovebird - 09-07-2022

(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


RE: How to validate field with brackets in name - JustJohnQ - 09-07-2022

Try changing button[10] in rules to button.*


RE: How to validate field with brackets in name - groovebird - 09-07-2022

(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.


RE: How to validate field with brackets in name - JustJohnQ - 09-07-2022

button.10 etc....

http://codeigniter.com/user_guide/libraries/validation.html#validating-keys-that-are-arrays


RE: How to validate field with brackets in name - groovebird - 09-07-2022

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

http://codeigniter.com/user_guide/libraries/validation.html#validating-keys-that-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


RE: How to validate field with brackets in name - Ahmed Haroon - 09-07-2022

@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.


RE: How to validate field with brackets in name - groovebird - 09-08-2022

@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


RE: How to validate field with brackets in name - Ahmed Haroon - 09-08-2022

(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.