Hi,

I have a custom module (I changed here in the example the name to "mymodule") where anonymous people can globally subscribe... I know there are other modules for that, but it didn't fit to my needs. It generates a block (with a really stupid tiny form text+checkbox), which I placed on every page in my site.

Without Boost, everything worked fine. But with Boost enabled, I get an odd behavior. I saw other issues similar here, but I didn't find exactly the same problem.

It looks like it handles correctly form_set_error but not drupal_set_message... in fact I think the problem could be form_validate vs. form_submit functions. Validation works fine, form_set_error draws the error after trying to submit a wrong mail (or even an empty value, since textbox is required), but drupal_set_message inside submit doesn't work as expected... code works right (insertions are made into DB), and it looks like message are stored into SESSION, but not displayed when required:

When I submit a valid mail, no message is shown. I can submit a valid mail many times, and message is never shown. But (after that) if I submit an invalid or empty mail, I see the alert with all previous messages, and the new one (with the wrong mail error).

In other test, after submitting the form with a valid address (no message is shown as I said) one time or more, if I visit another page in my site, the message/s is/are shown.

Initially, I thought it could be a Better Messages module issue, but it isn't since I replicate it with that module disabled.

Here is my pseudo-code:

function mymodule_formblock_validate($form, &$form_state){
    if(!valid_email_address($form_state['values']['mail'])){
        form_set_error('mail', t('Given mail address is not valid.'));
    }
}
function mymodule_formblock_submit($form, &$form_state){
    // if mail exists in DB
        drupal_set_message(t('You were already subscribed.'), 'warning');
    // else
        // Insert into DB
        // Actions
        drupal_set_message(t('Subscription successfully created.'));
}

Comments

bgm’s picture

Category: bug » support
Status: Active » Fixed

I'm not sure how to debug this, but keep in mind: after a POST, boost will set a cookie that will be removed after the next GET, to bypass the cache. (ex: to be able to view the result, view messages, etc).

From what you describe, you are hitting the cache after your POST. Check out the boost_cookie_handler() function for more information.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.