CodeIgniter Forums
Validate fields if checkbox is not checked - 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: Validate fields if checkbox is not checked (/showthread.php?tid=80618)



Validate fields if checkbox is not checked - eleumas - 11-22-2021

Hi, i would like validate with "required" some fields only if checkbox is not checked.
https://drive.google.com/file/d/1BIFWo1CyfnL0svglbSepN7rcAUYpttIJ/view?usp=sharing
Is possible? How can i do?

I thought which i could change checkbox in a dropdown and validate others fields only if has been selected a specific value from dropdown (in my case value 2).

PHP Code:
<select name="shipping-method">
<
option value="1">pickup in store</option>
<
option value="2">courier service</option>
</
select

This solution could be more easy? Any suggestion for me? Thanks.


RE: Validate fields if checkbox is not checked - sammyskills - 11-22-2021

I think you need the required_without validation rule.

See the docs for more information.