2

I am creating a custom form using the form api. I'd like to reuse the price field used by commerce, but I don't know how to include their form type in my own form.

8
  • possible duplicate of Price field with Currency outside of commerce and ubercart
    – beth
    Commented Aug 26, 2014 at 19:43
  • 1
    The question link in my opinion does not show me how to add it to a form using the form api.
    – Bobby
    Commented Aug 26, 2014 at 19:52
  • 1
    There's no "currency" or "price" or "money" fieldtype in the form API in core.
    – beth
    Commented Aug 26, 2014 at 19:54
  • I do have Drupal Commerce installed all ready. Is it simple to add the price field from that module to my form?
    – Bobby
    Commented Aug 26, 2014 at 20:01
  • Yes I think it is just like any other field, but 'type' would be the type defined by Commerce Price instead of a core type. If you look at the code of the field in the Commerce module it should be the same as that.
    – beth
    Commented Aug 26, 2014 at 20:08

1 Answer 1

1

this works for me

$form['price'] = array(
  '#type' => 'commerce_price',
  '#title' => $this->t('Price'),
);

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.