1
Array
(
    [items] => Array
        (
            [0] => Array
                (
                    [nid] => 164
                    [module] => uc_product
                    [remove] => Remove
                    [title] => Strokes1
                    [data] => a:4:{s:10:"attributes";a:0:{}s:9:"shippable";s:1:"0";s:12:"restrict_qty";s:1:"0";s:6:"module";s:10:"uc_product";}
                    [qty] => 2
                    [description] => 
                    [cart_item_id] => 200
                )

            [1] => Array
                (
                    [nid] => 165
                    [module] => uc_product
                    [remove] => Remove
                    [title] => Strokes2
                    [data] => a:4:{s:10:"attributes";a:0:{}s:9:"shippable";s:1:"0";s:12:"restrict_qty";s:1:"0";s:6:"module";s:10:"uc_product";}
                    [qty] => 1
                    [description] => 
                    [cart_item_id] => 203
                )

            [2] => Array
                (
                    [nid] => 166
                    [module] => uc_product
                    [remove] => Remove
                    [title] => Strokes3
                    [data] => a:4:{s:10:"attributes";a:0:{}s:9:"shippable";s:1:"0";s:12:"restrict_qty";s:1:"0";s:6:"module";s:10:"uc_product";}
                    [qty] => 1
                    [description] => 
                    [cart_item_id] => 204
                )

        )

    [update] => Update cart
    [checkout] => Checkout
    [form_build_id] => form-5c5819d5418df14f08153f1ce15d6acc
    [form_token] => 2341b9068b8ffb7454d267b22e572d7d
    [form_id] => uc_cart_view_form
)

I'm using form_set_error to display the error messages if there is no product.

My Issue is:

For example, I am having 3 products in the checkout page.

When I clicks submit I need to validate that all the products are available.

Here, let us consider if the second product is not available I am showing the error message "Product Stroke 2 is not available".

But all the check boxes in the cart is highlighted

Because I had set form_set_error to items element.

How can I set form_set_error for every individual element.

What I have given to display error message:enter image description here

form_set_error('items', 'Not available');

Kindly guide me how to resolve the issue. I am using ubercart module with drupal 6.

3

There is a comment on the API page for form_set_error which explains how to set a form error on a subelement of a form item.

From the comment:

form_set_error('field_name][i][value', t('Your message'));
  • I don't know why I was voted down, but the link answers the question. If not, please explain why. – Countzero Mar 22 '12 at 9:52
  • I didn't downvote, but just posting links isn't a good answer. From drupal.stackexchange.com/questions/how-to-answer, "A link to a potential solution is always welcome, but please add context around the link so your fellow users will have some idea what it is and why it’s there . Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline." – mpdonadio Mar 22 '12 at 10:36
  • Well, I can understand this policy, but when api.d.o will go offline, all this site will be useless anyway. I'll try to complete my answer, though. – Countzero Mar 22 '12 at 11:02
  • +1 for the updated answer according to SOF strategy.. And its working fine... Great : Cheers :) – Fero Mar 23 '12 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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