I need some suggestion to add some fields to the "Add to cart" page.

Out of many products, one of the product requires some user information to be filled before proceeding to "Add to cart" process. I am selling a product of type "Exam". Before buying Product of type "Exam" (Before adding to cart), user has to input his person details like name, address, DOB and other mandatory details without which he is not able to proceed.

Could you please guide me, how to achieve this?


Shall I use Product Attribute fields to capture user inputs over product display page? As this information is not associated with the Product, but with the order and need to be captured before Add to Cart button is clicked.


3 Answers 3


Thanks all of you for your valuable time and suggestions. More or less all suggestions 'll be required in near future. I have up-voted all of you for your help. However on other side I got the answer, what I was looking for.

It sounds like you need the Customizable Products module.

Once you have that module installed, you can go to Administration > Store > Configuration > Line item types. Add a custom line type and add as many custom fields there as you'd like. You'll see - the interface for adding fields to the custom line type is the same as when you create a content type, so it's easy to use.

Then, when you've added all the customer info you need in your new line item, go ahead and modify your 'Exam' product to include those fields in the product display. Hit the 'Display' settings for the content type, and configure the settings for the 'Add to cart' field. Make sure you choose the correct line item for it to use and Save!

Helpfull screencast could be found at http://vimeo.com/36106455


Try this:

 * Implements hook_form_alter().
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if (strstr($form_id, 'commerce_cart_add_to_cart_form')) {
    // Add the required form elements here.

    // Add your custom validation function.
    $form['#validate'] = array('mymodule_custom_form_validation');

function mymodule_custom_form_validation($form, &$form_state) {
  // Do your validation here.

Help links: http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#validate, http://drupal.org/node/732108

  • Hello subhojit777, Thanks for help. Shall I add above mentioned input required fields as Product "Attribute" Fields?
    – Asif Mulla
    Commented Jan 23, 2013 at 7:06
  • If you want to associate person details with the product then yes, add the fields as Product "Attribute" fields Commented Jan 23, 2013 at 7:12
  • I just saw your question update: There is no need to add the fields as product attribute fields. Also when you click on "Add to cart" button a new "order" object gets created, if no "order" for that user exists, if there is an "order" object then it gets updated with line items. Also the "order" object captures the user id. Commented Jan 23, 2013 at 7:13
  • Yes product attribute fields won't be an options, since Product Attributes allows only to create selectable, not editable fields when adding to cart.
    – Asif Mulla
    Commented Jan 23, 2013 at 9:21
  • So only form alter is options to add extra fields? Or some functionality/module exists to add editable text fields on Add to cart page?
    – Asif Mulla
    Commented Jan 23, 2013 at 9:25

I would say you need to rethink that checkout process.

The order is created after the first product is added to a cart for that user.

The information you are looking to add belongs on a Commerce Customer Profile on the Commerce Order (e.g "Billing information").

You can create a customer profile type with:

or else:

For example, a new customer profile type called "Personal information".

That way, the data is stored for each customer with the order itself, as part of the customer profile, where it belongs.

Alternatively, you might be able to do something with adding a field to the line item type, maybe even referencing a commerce customer profile entity, but that would need more evaluation.

  • Hi David, Thanks for suggestion. If I am using new Profile then for every Product user has to input "Personal details", whereas I need to capture user input if and only if Product of type "Exam" is added to cart? How could I achieve this?
    – Asif Mulla
    Commented Jan 23, 2013 at 10:00
  • That req would be a bit more tricky in that you would need to implement hook_commerce_checkout_pane_info_alter inspect the products in the cart and then set $checkout_panes['info']['enabled'] = 0; // or 1 to enable that checkout pane Commented Jan 23, 2013 at 10:17

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.