Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Bloody checkboxes...
#1

[eluser]johnwbaxter[/eluser]
If someone could give me a hand i would be ever so grateful!

I have some checkboxes that get ticked, then that page is refreshed with updated values and the checkboxes are shown again with the ones that were selected still ticked.

What i want is that when the checkbox is unticked it stays unticked after refresh.

I'm saving the state of the checkbox in the session and so really i simply want to know how to detect that the checkbox is not ticked from the post data so that i can unset it from the session data.

I cant get it to do what i want, it is driving me mad!

Help!
#2

[eluser]sparkling tux[/eluser]
If I understand your intentions correctly,
Code:
array_diff()
// returns an array containing all the values of array1  that are not present in any of the other arguments
should help you.
You probably know, that form sends only the checkboxes, that is ticked.
Thus
Code:
// getting newly ticked checkboxes
$checked = array_diff($_POST['checkboxes'], $checkboxes_in_your_session);

// getting unticked checkboxes
$unchecked = array_diff($checkboxes_in_your_session, $_POST['checkboxes']);
#3

[eluser]johnwbaxter[/eluser]
I see what you are saying yes. I don't have any trouble with some being unticked, it's when all are unticked.

I'm trying to say something like if !isset $this->input->post('checkboxes') then unset_sessiondata but that doesn't seem to get me anywhere.

Thanks for your thoughts though.
#4

[eluser]sparkling tux[/eluser]
I've reread your original post and I realy think you should pay attention to my example.
Quote:i simply want to know how to detect that the checkbox is not ticked from the post data so that i can unset it from the session data
As I said, POST doesn't send what's not ticked. So the only way is to find the difference between what was ticked before and what is ticked now, and the state that you're saving in session is of great help here.

On the other side, may be the problem is in the syntax or somewhere else, so if you'd provide some excerpts from your code it would be much easier to help.
#5

[eluser]johnwbaxter[/eluser]
Yes perhaps you are right, although it would be more of a hack i think.

The checkboxes are one big list and they get passed as an array. They are the only thing that gets passed in post i think.

Perhaps if i had it so that something else got passed in post then i could use that array_dif otherwise post is empty.

I am very grateful for your help, i hope you didn't think i was just disregarding your suggestion out of hand.
#6

[eluser]obiron2[/eluser]
to force the $_POST use a hidden field on the form.
#7

[eluser]sparkling tux[/eluser]
If there's no POST and according to the state in the session something is ticked - it means the user unticked everything, isn't it?
#8

[eluser]johnwbaxter[/eluser]
Yes it does, that is very true but i cant get this to work
if $this->input->post('contacts') == FALSE

perhaps i'm doing this all the wrong way round...
#9

[eluser]sparkling tux[/eluser]
I can suggest you var_dump($this->input->post(’contacts’)) (and possibly also var_dump($_POST[’contacts’])) and see who is who and whats'up there.
#10

[eluser]johnwbaxter[/eluser]
I think what is killing me is that the ci way of doing post is doing the if check for me which i really want to do myself.

I'll see what some dumps throw out. Cheers.




Theme © iAndrew 2016 - Forum software by © MyBB