Welcome Guest, Not a member yet? Register   Sign In
Possible issue with set_checkbox + jquery + form validation?
#1

[eluser]RaGe10940[/eluser]
Hello, I am not new to form validation nor am I not new to set_(what ever, radio, checkbox, value, etc) in CI.

However I can not for the life of me get this part to work for me.

Scenario :

I have two different "views" for the same exact page. If your account is a student account you can not see two check boxes (view 1)

if your account is a staff member you can see the check boxes (thats the "second" version of the view)

so they are both exactly the same except for the 2 added check boxes.

With those two check boxes, I have a id set to them so if the check boxes are clicked the jquery will react with bringing up a drop down menu, and the other check box will remove two input fields.

that works fine, but if per say I run through form validation the value (the checked value) does not get saved so a staff member would have to re-check the check box.

Is this a known issue? This is my form check box code :

Code:
<font color="#ff0000" size="2">Check Box If You Do Not Have An A-Number</font>&lt;input type="checkbox" name="student" value="yes" id="current" &lt;?php echo set_checkbox('student', 'yes'); ?&gt;/&gt;

and

Code:
<font color="#ff0000" size="2">If student is on the phone check box</font>&lt;input type="checkbox" name="phone" value="yes" id="phone" &lt;?php echo set_checkbox('phone', 'yes'); ?&gt;/&gt;

I have other places on my page where I use set_radio and that works fine, its literally these two only check boxes. This is confusing me.

If you guys need to see the jquery let me know.
#2

[eluser]TheFuzzy0ne[/eluser]
Do you have rules set up for those checkboxes and the radiobutton?
#3

[eluser]RaGe10940[/eluser]
for the name=phone check box no and also for name= student check box no,

They are optional, are you saying I have to set up rules for them?
#4

[eluser]TheFuzzy0ne[/eluser]
Yes. You need to set up an empty rule in order for them to be available via the form validation library.

Code:
$this->form_validation->set_rules('phone', '', '');

Hope this helps.
#5

[eluser]RaGe10940[/eluser]
Honestly, I would have never thought of doing that? Where in the manual did that come up? Or did you go through the same ordeal that I have been going through?
#6

[eluser]TheFuzzy0ne[/eluser]
Yes, I came across this problem a couple of years ago, so I traced back the set_value() helper function and discovered that if a rule was not set for the field, the the appropriate entry in _post_data was not set. set_value() get's it's values from the validation object if it's instantiated, otherwise, it takes it straight from the $_POST array. So if you want a value for any field and have the form validation library loaded, you must define a rule for it (even if the actual rule is empty).

I encourage you to check it out and see for yourself. Smile

Hope that makes sense. I've got someone chatting away to me as I type this, and I'm pretending that I'm listening...




Theme © iAndrew 2016 - Forum software by © MyBB