Welcome Guest, Not a member yet? Register   Sign In
custom validation dinamic
#1

hi there is a way to send to parameter to a validation rule ?

Code:
    public function required_if($first_parameter,$second_parameter)
    {

    if(!$first_parameter ){

    return true;

    }else if($first_parameter AND !$second_parameter){
   
    return false;
   
    }else{
   
    return true;
   
    }
   
    }


If is possible how can i pass they in rules ?
Reply
#2

See https://codeigniter4.github.io/userguide...parameters
Parameters using as "required|required_if[first,second]"
Simple CI 4 project for beginners codeigniter-expenses
Reply
#3

(This post was last modified: 05-03-2024, 10:37 AM by pippuccio76.)

(05-03-2024, 10:22 AM)ozornick Wrote: See https://codeigniter4.github.io/userguide...parameters
Parameters using as "required|required_if[first,second]"

my first parameter is a radio button , 0 or 1 value ar always passed but i must check if is 0 or 1 ad check other parameter passed .

I have a form with more than 10 field that must required only if first parameter is 1 .
My idea was send parameter dinamically ,without $data['name_of_first_parameter] and $data[name_of_second_parameter] , because first parameter is always same name but second change for every field and i must create ten custom rules (instead one), it's possible ?
Reply
#4

I didn't understand the question well.
Perhaps for your comparison you need to make parameters for 10 radio buttons.
For example, get_radio_params() (first=>1,second=2,...)
Then use them for the form and for validation? These parameters will be located in $data in the rules
Simple CI 4 project for beginners codeigniter-expenses
Reply
#5

hi i have 1 radio button :
radio1 (0 or 1) and 20 field.
10 field :
field 11 ,field 12 field 13 , fiel14 , field 15 , field 16 , field 17 , field 18 , field 19 ,field 20
must be required only if radio1 is set to 1 .
With the actual validation i must create 10 custom rules :
-control if radio is 1 anda field 11 is set
-control if radio is 1 anda field 12 is set
-control if radio is 1 anda field 13 is set
......
-control if radio is 1 anda field 20 is set

i would be create only a rules :
i want create one role with 2 parameter :radio values and another parameter
another parameter is the value of field 11,12,13....20

It's possible ?
Reply
#6

I'm telling you, use $data for your rule.
require_if[radio1]
In $data, you will have the rest of the buttons: radio2...radio20
Check their availability at radio1. What is the problem?
PHP Code:
if ($value !== '' && in_array($data'radio2',...'radio20')) { return true; } 
Simple CI 4 project for beginners codeigniter-expenses
Reply




Theme © iAndrew 2016 - Forum software by © MyBB