Welcome Guest, Not a member yet? Register   Sign In
Checkboxes, posting the form, re-displaying the checkboxes with new selections not working
#1

[eluser]Kinsbane[/eluser]
I'm working on a way for people to manage their email subscriptions to a bunch of different topics. If they want to manage them, they type their email address into a box and it loads their subscriber information in a fieldset at the top, and two columns of checkboxes for their subscriptions underneath that.

When they submit the form, I am able to have a correct email go out to the user and it lists there the subscriptions they chose. What I want it to do is, after the form is submitted, it shows the form again, but this time with their new subscriptions checked in the appropriate box. But it's not happening that way. When the form gets reloaded and it re-pulls the subscriptions from that user, I can echo out the array for the subscriptions in the view, but for some reason, the form is not checking off the appropriate boxes.

Here's the code that pulls the subscriber information and the subscriptions when you first type your email address into the box to look up the info:
Code:
/* controller: support.php/subscriptions */
$data['subscriber'] = $this->service->getSubscriberByEmail($this->input->post('email'));
            $subscriptions = $this->service->getCurrentSubscriptions($data['subscriber']['subscriber_id']);
            //print_r($subscriptions->result_array());
            foreach($subscriptions->result_array() as $sub)
            {
                $ptypename = $this->service->getPTypeName($sub['pt_id']);
                $data['subscriptions'][$sub['pt_id']] = $ptypename['pt_name'];
            }

That all does as it's supposed to (after passing validation). Here's the code in the View where I loop through the subscription topics to display their checkboxes and labels. Again, on initial view of this, these boxes are checked appropriately.
Code:
/* view: subscribe/update_form.php */
<?= form_fieldset('Subscription Topics'); ?>
        <p style="margin: 0; padding: 10px 0 5px 0;">Choose one or more topics to subscribe to. Unchecking every box will result in no updates and notifications by email.</p>
        &lt;?= form_error('subscriptions[]'); ?&gt;
        &lt;? foreach($ptypes as $type): ?&gt;
        <label for="&lt;?= $type['pt_id']; ?&gt;" style="width: 320px; clear: none;">
        &lt;?
        
        if(in_array($type['pt_name'], $subscriptions))
        {
            $sel = TRUE;
        } else
        {
            $sel = '';
        }
        ?&gt;
            &lt;input type="checkbox" value="&lt;?= $type['pt_name']; ?&gt;" style="width: auto;" name="subscriptions[&lt;?= $type['pt_id']; ?&gt;]" &lt;?= set_checkbox('subscriptions['.$type['pt_id'].']', $type['pt_name'], $sel); ?&gt; /&gt;
            <span class="label" style="margin-left: 20px;">&lt;?= $type['pt_name']; ?&gt;</span>
        </label>
        &lt;? endforeach; ?&gt;

Now, the thing here is, and I think this is key, is the view file update_form.php is used in two different methods in this controller. But the view displays specific data, and the issue I have is that after the selections get posted to the database, and the form is reloaded, the new selections aren't reflected.

I am using the same code in the controller method above in the method that runs the processing of the selections.

I just don't know what to do because I would like to show the user right away that their choices were saved and not have to rely on the email I get for confirmation. My other option is to redirect and show a message that says it was saved.




Theme © iAndrew 2016 - Forum software by © MyBB