Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

I'm programming an EE extension, and in the save_settings() method, if I redirect() (after unsuccessful data validation), the message stored in the set_flashdata() method doesn't show. If I comment the redirect and let the method put the user back in the main extensions page, then the flashdata shows up fine. It's only if I redirect that the data isn't shown.

This is my save settings method - as near as I can tell I'm not doing anything out of the ordinary - it's mostly boilerplate as near as I can tell. I'd be very appreciative of anybody that can shed light on this...

function save_settings(){

    // no unauthorized access
    if (empty($_POST)) {
        show_error($this->EE->lang->line('unauthorized_access'));
    }

    // get the routestring then convert it to an array
    $routestring = $this->EE->security->xss_clean($this->EE->input->post('routes'));
    $results = $this->routes_to_array($routestring);

    // if the conversion was ok:
    if ($results['status'] == 'success') {

        // update db
        $this->EE->db->where('class', __CLASS__);
        $this->EE->db->update('extensions', array('settings' => serialize(array('routes' => $results['results']))));

        // set flash data
        $this->EE->session->set_flashdata('message_success', "Routes updated.");

    // if something went wrong during conversion:  
    } else {

        // set flash data then redirect back to edit screen
        $this->EE->session->set_flashdata('message_failure', $results['message']);

        // IF I COMMENT THE FOLLOWING LINE, THE FLASH DATA SHOWS UP FINE
        $this->EE->functions->redirect(BASE.AMP.'C=addons_extensions'.AMP.'M=extension_settings'.AMP.'file=apsdsm_bossyboots');
    }              
}

OK, this is my view file - as far as I can tell this is as boiler plate as it gets. More boiler plate than a dish that's been held in scalding water for ten minutes.

<?php echo form_open('C=addons_extensions'.AMP.'M=save_extension_settings'.AMP.'file=apsdsm_bossyboots'); ?>

<table class="mainTable" border="0"cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th>
                Routes
            </th>
        </tr>
    </thead>

    <tbody>

        <tr>
            <td>

                <?php echo form_textarea(array('name'=>'routes', 'value' => $routestring)) ?>

                <?php echo form_submit('submit', 'Update Routes', 'class="submit"') ?>
            </td>
        </tr>
    </tbody>
</table>

<?php echo form_close()?>
share|improve this question
    
I think something else is going on here. That is almost exactly the same code I've used many times. Can you check Chrome/Firebug Network tab and make sure there aren't any stray redirects occurring? –  Adrian Macneil Dec 29 '12 at 20:09
    
OK: so I checked the Network data: the only redirect going on there is the one in my code, and it looks like the ext_flash cookie is being set correctly - I can see the correct error data being passed along in the headers, but it's not displaying... –  apsdsm Dec 30 '12 at 2:21
    
Sorry, not ext_flash, I meant exp_flash. –  apsdsm Dec 30 '12 at 2:36
    
What method you using to display the flash data? –  Adrian Macneil Dec 30 '12 at 19:10
    
I'm just letting the Expression Engine control panel take care of it - So, after the redirect I'm not including any special code in my 'save_settings' method or anything. I swear I've done that before and it's worked fine... –  apsdsm Dec 31 '12 at 1:12
show 4 more comments

1 Answer

I'm not positive if this will work or not, but the CodeIgniter Session library has a method for keeping flashdata for more more request, I'd imagine this would help here.

Try adding this before the redirect: $this->EE->session->keep_flashdata('message_failure');

share|improve this answer
    
Unfortunately, though that method is declared in the CI lib, it doesn't seem to be in the EE version... Flags an undefined error message... Thanks for the suggestion though, I appreciate it! –  apsdsm Jan 2 '13 at 16:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.