Welcome Guest, Not a member yet? Register   Sign In
Yet Another Checkbox checking in the form thread, check it out and help me :(
#1

[eluser]Kinsbane[/eluser]
Followed the code in this thread: http://ellislab.com/forums/viewthread/73012/P0/ to adjust the validation class. But, I'm having no luck.

Short of it: Users can check one or more checkboxes in different groups ($products[], $documents[], etc) to receieve email updates. When the page is loaded, though, the data gets properly retrieved from the database, but no checkboxes are checked.
Here's what I've got:
Code:
if ($query->num_rows > 0) { // if the current user is in the database
            $row = $query->row_array();
            //die(print_r($row));
            $products = explode(",", $row['products']);
            $documents = $row['documents'];
            $events = explode(",", $row['events']);
            $tools = explode(",", $row['tools']);
            $managers = explode(",", $row['managers']);
            $partners = explode(",", $row['partners']);
            
            //die(print_r($products));
            $fields['products'] = $products;
            $fields['documents'] = $documents;
            $fields['events'] = $events;
            $fields['tools'] = $tools;
            $fields['managers'] = $managers;
            $fields['partners'] = $partners;
            
            $this->validation->set_fields($fields);
            
            $this->validtion->documents = $documents;
            $this->validation->products = $products;
            $this->validation->events = $events;
            $this->validation->tools = $tools;
            $this->validation->managers = $managers;
            $this->validation->partners = $partners;
            
            $data['page']['page_title'] = $this->config->item('notif_update_title');
        } else { // if the user hasn't wanted notifications til now (no row in the table with their user ID, notice I didn't setup for the validation to show checked checkboxes)
            $data['page']['page_title'] = $this->config->item('notif_add_title');
        }

Now, I'm templating my views out and so the form with all the checkboxes is in its own file, called like so:
Code:
$this->load->view('general/start_page', $data);
$this->load->view('general/menu_primary');
switch ($this->uri->segment(1)) {
    case "products":
    case "documents":
    case "reference":
    case "events":
    case "tools":
    case "manage":
    case "partners":
    case "home":
        $this->load->view('general/menu_secondary.php');
    break;
}
$this->load->view('notifications_form', $data);
$this->load->view('general/end_page');

Finally, my form with the checkboxes looks like this:
Code:
<?= form_open('notifications/update'); ?>
              
       <fieldset>
           <legend>Manage Your Notification Settings</legend>
                  
           <ul>
                 <li>Products
               <ul>
                   <li>&lt;input type="checkbox" name="products[1]" value="1" &lt;?= $this-&gt;validation->set_checkbox('products', '1'); ?&gt; /> <label for="products">Add, Change or Remove Product</li>
                   <li>&lt;input type="checkbox" name="products[2]" value="2" &lt;?= $this-&gt;validation->set_checkbox('products', '2'); ?&gt; /> <label for="products-photo">Add or Change Product Photos</li>
                   <li>&lt;input type="checkbox" name="products[3]" value="3" &lt;?= $this-&gt;validation->set_checkbox('products', '3'); ?&gt; /> <label for="products-stencil">Add or Change Product Stencil</li>
                   <li>&lt;input type="checkbox" name="products[4]" value="4" &lt;?= $this-&gt;validation->set_checkbox('products', '4'); ?&gt; /> <label for="products-bulletin">Add or Change Product Bulletin</li>
               </ul>
           </li>
        </ul>
&lt;!-- etc, etc --&gt;
</fieldset>
&lt;?= form_close(); ?&gt;

However, I have checked the update mechanism and the data gets processed and inserted correctly. The only issue is actually setting the checkboxes in the form itself, which I can't see why it's not.
#2

[eluser]Sumon[/eluser]
Try to use
Code:
&lt;input type="checkbox" name="products[]" value="1" &lt;?php echo set_checkbox('products[]', '1'); ?&gt; /&gt;
&lt;input type="checkbox" name="products[]" value="2" &lt;?php echo set_checkbox('products[]', '2'); ?&gt; /&gt;
//and so on
#3

[eluser]Kinsbane[/eluser]
That returns an error: Call to undefined function: set_checkbox()

Sad

Thing is, I had this working a couple weeks ago. But since I moved to an auth library from the CI wiki, something's changed to make this not work and I can't remember what it was... and there happens to be no backups, to make things worse Sad
#4

[eluser]Sumon[/eluser]
what about?
Code:
&lt;input type="checkbox" name="products[]" value="1" &lt;?php echo $this-&gt;validation->set_checkbox('products[]', '1'); ?&gt; />
&lt;input type="checkbox" name="products[]" value="2" &lt;?php echo $this-&gt;validation->set_checkbox('products[]', '2'); ?&gt; />
//and so on
#5

[eluser]Kinsbane[/eluser]
Here we go! I had found this thread back in April and this is what I had used when it worked.

Just re-did it (after upgrading to 1.6.3) and now it works as it should!




Theme © iAndrew 2016 - Forum software by © MyBB