Monday 15 March 2010

php - Include also unchecked boxes in the POST variable - multiple checkbox -


I am using the code below to get value from a multi checkbox. {Update_comment_meta ($ check, 'idea') ( ('$ _ POST [' check_list '])) {foreach ($ _ POST [' check_list '] $ check) {update_comment_meta ($ check) , 1); }}

The problem is that this code is apparently putting in the array $ _ POST ['check_list'] checked values ​​only

I need the function update_comment_meta also on unselected values, perfom by inserting '0' as a third parameter instead of '1'.

For more details, I generate the HTML form code:

  & lt; Form action = "id =" primaryPostForm "method =" POST ">  comment_id, 'idea', true) == 1) {? & Gt; & lt; input type = "checkbox" name = "check_list" [] "Value =" & lt ;? Php ek $ co- & gt; Comment_id ;? & Gt; "check =" check "& gt; & lt ;? php} other {? & Gt; input type =" checkbox "name =" check_list [] "value =" & lt ;? Php echo $ co- & gt; Comment_id ;? & Gt; "& gt; & lt ;? php}}    

Your help is always appreciated.

Sending unchecked values ​​is not easy to post to some extent. The better solution is to use the checkbox in a way You can easily use it in a post page.

Use the hidden input with the checkboxes. The checkbox gives preference to the hidden input.

  & Lt; form & gt; Input type = 'checkbox' value = '1' name = 'check_box_con' & gt; & lt; / form & quot; input type = 'hidden' value = '0' name = 'check_box_en' & gt; Gt;   

Now, both have the same name after the submission, check_box_con will show hidden field values ​​if unchecked, override and display other originals.

To see more >

No comments:

Post a Comment