For certain products in my ubercart catalog, I need to show a legal disclaimer before actually adding them to the cart. I was thinking to use hook_uc_add_to_cart for this, because it allows me to return a message in the result array :


I could return a html enriched message holding the anchor to the final cart addition, in case the legal notice is read and confirmed.

For example : How do I translate this submit input form to a query string like alternative ?

<input class="node-add-to-cart form-submit" type="submit" id="edit-submit-144" name="op" value="Add to cart">

As an alternative I could ask the 'shopper' to hit this submit a second time as confirmation.

Then: To bypass the hook a second time, I could add a confirmed Boolean into the $data array which is returning into this hook as 3th parameter.

If I add this Boolean into the $data as a new key->value pair, will it be available again in the next submission ?

1 Answer 1


I was able to solve this issue using the first answer on this stackoverflow question : https://stackoverflow.com/questions/10490253/how-to-save-a-session-variable-in-drupal-7

In general: Drupal's static $_SESSION array variable allows to store key=>value pairs between different node pages, in my case the same page.

My code snippet inside uc_product_minmax_uc_add_to_cart hook :

    if (!empty($disclaimer)) {

        $confirmed = lists_session("s_key");

        if(! $confirmed) {

            $message[] = t($disclaimer, array('@qty' => $minmax->pmin_multiple, '!item' => $node->title));
            $result[] = array(
                'success' => FALSE,
                'message' => theme_item_list(array('items' => $message, 'title' => t('Read this note from medical department before confirming your reservation :'), 
                'type' => 'ul', 'attributes' => array())),
                'silent'  => FALSE,
            lists_session("s_key", TRUE);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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