set_checkbox (partially resolved) |
[eluser]ivston[/eluser]
Any idea why the following code does not set the checkbox properly ? form-validation rule: Code: array('field'=>"cat1[]", 'label'=>"Cur", 'rules'=>''), form: Code: for (... here I set $val ...) - the form-validation library is properly loaded. - it sets properly as checked the fields, but keep them always checked after the interaction. Thanks!
[eluser]bigtony[/eluser]
set_checkbox() is intended for use when you are not using the form_checkbox() function: Code: <input type="checkbox" name="cat1[]" value="<?php echo $val; ?>" <?php echo set_checkbox('cat1[]', $val); ?> /> Code: // assumes $val can only be 0 or 1...
[eluser]ivston[/eluser]
I also had tried, this, similar to to your post, but it still does not work.. Code: echo "<input type='checkbox' name='cat1[]' value='".$val."' ".set_checkbox("cat1[]",$val,TRUE)";
[eluser]bigtony[/eluser]
[quote author="ivston" date="1258495038"]I also had tried, this, similar to to your post, but it still does not work.. Code: echo "<input type='checkbox' name='cat1[]' value='".$val."' ".set_checkbox("cat1[]",$val,TRUE)"; It's not similar enough to my post. For a start, you are still passing 3 parameters to set_checkbox() when it only accepts 2, and you're not ending the input tag.
[eluser]ivston[/eluser]
- the missing closure of the input tag is just a tipo in the post; in the code it's ok. All the rest is the same, except the default value which I do need to set. - as for the "only" two input params, how about this declaration in /system/libraries/Form_validation.php: Code: function set_checkbox($field = '', $value = '', $default = FALSE) Moreover, how about this info in the CodeIgniter documentation (http://ellislab.com/codeigniter/user-gui...ation.html) of set_checkbox(): "Permits you to display a checkbox in the state it was submitted. The first parameter must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE)." Any valuable idea about my problem ? I have no problem using this class in other, more simple cases. pp. I just noticed that I autoload "validation". However, the class that actually permits a default value of set_checkbox() is FormValidation. I don't know how this could explain the story, since I did some control print_r()'s in FormValidation.php; some of which did print something, so this library seems to have been loaded. (now I can not check whether autoloading "formvalidation" is possible and whether this would resolve my problem).
[eluser]ivston[/eluser]
:-) I partially resolved the problem: in this case one must autoload or load 'form_validation' instead of 'validation'; the former does- the later is obsolete and does not- supports defaults for set_checkbox there is still one problem: autoloading rules corresponding to my controller-class / function does not work here (for other functions it does work). I do it with this code and I don't see any problem with it: Code: $config=array( I resolved the missing autoload by explicitly setting the rules in my controller, such as: Code: $this->form_validation->set_rules('cat1[]',"myLabel1",'xss_clean') So, admins, please, tell me what is wrong with my rules autoloading? Then, please, update the autoloading example in config/autoload.php so newbies don't loose time for such naive problems. cheers
[eluser]Samuurai[/eluser]
Is there a better solution than this? I just spent a couple of hours setting up the form_validation config file.. surely set_checkbox can be made to work with my configuration too..?
[eluser]ivston[/eluser]
my final solution was not using form validation at all; to eventually speedup the code. Here is an abstraction of my solution: in controller initialization: Code: session_start(); in a controller function that responds to the post: Code: $Cat=$this->input->post('cat'); in a viewer function that prepares the code: Code: $ind=1; for live demo, see Artjsta - the artists site It's in italian, but the checkbox functionality is clear |
Welcome Guest, Not a member yet? Register Sign In |