Multiple ignore-fields for is_unique-function |
I'm having some issues with the Codeigniter 4 validation rules. I'm using the is_unique function within the ruleset in Order to except one single row from the validation.
The problem here is that there are two fields in the table that need to be checked: Code: 'episodeTitle' => [ Is it possible, to make the exception depending on 2 or more fields? I want to check the episodeID AND the podcastID not only one of these values.
I'm not sure I am interpreting your question correctly, but in general, if you need two fields to be unique, you will need to create a separate validation rule for each field.
If you are trying to check if the value of the field is unique in two different columns in the same row (I'm not sure why you would ever want to do this) try using the is_unique rule twice, once for each column. I've never done it before, but it might work. PHP Code: 'rules' => 'required|max_length[100]|is_unique[table.column1,table.columnID,{columnID}|is_unique[table.column2,table.columnID,{columnID}]', Please note the correct syntax for the ignore value placeholder described in the documentation: https://codeigniter.com/user_guide/libra...aceholders. If that doesn't work, you will need to create your own custom validation rule. Check out the documentation to get started: https://codeigniter.com/user_guide/libra...stom-rules.
Hey, thanks for your answer. Unfortunately, that does not work.
You're interpreting correctly. My issue is the following: I have a table for podcast Episodes. The Episodes are referring to a podcastID, so it can be possible that there are two episodes for two different podcasts but they have the same title. So when i use is_uniqe with episodeID as the only exception, another episodeID with the same title could be found but with another podcastID. That's why i need two exceptions.
Every rules list for check one input text field
- So, if you want to check multi than use your custom code or query Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams
I was able to fix the issue. I made custom function for the validation to check 2 database fields:
Code: public function is_unique_multiple(string $str = null, string $field, array $data): bool This ensures that entries with other podcastsIDs will not interfere with the validation |
Welcome Guest, Not a member yet? Register Sign In |