6

I am struggling with using additional custom order fields. (Added in the Craft Commerce settings at "order fields", in the field layout manager)

I try to update them like this in the checkout process:

<form method="POST">
    <input type="hidden" name="action" value="commerce/cart/updateCart">
    <input type="text" name="myCustomField" value="Test123">
    ...
    <input type="submit" value="Update Custom Field">
</form>

But in the Order in the CP, the field stays empty. Do I have to use another name for the field, like fields[myCustomField] or whatever?

I can update them in the CP, but not from the front-end...

12

Correct, you need to use fields[customFieldName] as the input name.

The following form should do it:

<form method="POST">
    <input type="hidden" name="action" value="commerce/cart/updateCart">
    <input type="text" name="fields[myCustomField]" value="Test123">
    ...
    <input type="submit" value="Update Custom Field">
</form>
  • Sweet! Is there also a way to validate those fields? – exophunk Jan 6 '16 at 8:24
  • Validation would need to be front end only for now. – Luke Holder Sep 18 '16 at 0:51

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.