# How to save and display custom field values from frontend in shopware6?

**URL:** <https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848>\
**Category:** Programming (EN)\
**Created:** [8. Januar 2020 um 04:59 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848 "2020-01-08T04:59:16Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [8. Januar 2020 um 04:59 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/1 "2020-01-08T04:59:16Z")

</div>

I have created a custom fieldset and a custom field from backend settings.&nbsp;

I want to do the following

1. Save the custom field value from the customer registration page.

2. Display the custom field value in the customer profile page

3. Update the custom field value on profile update

How to do these in shopware6?

---

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [9. Januar 2020 um 04:55 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/2 "2020-01-09T04:55:07Z")

</div>

My custom field name is name=“enable\_abandoned\_cart\_notification\_email”

I want to save the value during customer registration

Is it automatically save?

What will be the name(it is a checkbox field)?

name=“customer[customFields][enable\_abandoned\_cart\_notification]”

or&nbsp;

name=“customFields[enable\_abandoned\_cart\_notification]” ?&nbsp;

In shopware 5 it will be automatically saved(Free text field).

&nbsp;

---

<div class="post-metadata">

**Author:** ![markenwirt](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@markenwirt](https://forum.shopware.com/u/markenwirt)\
**Post date:** [28. Januar 2020 um 12:57 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/3 "2020-01-28T12:57:13Z")

</div>

We are also&nbsp;dealing with that same problem. We want to extend the register form with a custom field, which was set up in backend.&nbsp;Have you already found a solution for that? We tried a lot of combinations in the register form, but none worked.&nbsp;From my point of view, the mapping function for custom\_fields&nbsp;in the registration service isn´t implemented yet?&nbsp;

---

<div class="post-metadata">

**Author:** ![mdoroci](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mdoroci](https://forum.shopware.com/u/mdoroci)\
**Post date:** [28. Januar 2020 um 13:24 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/4 "2020-01-28T13:24:10Z")

</div>

Hi,

I am also struggling in this part. I am adding a text in the Custom field, and I want to do Data mapping with this field in the administration. Did anyone find a solution to that?&nbsp;

---

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [29. Januar 2020 um 04:12 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/5 "2020-01-29T04:12:51Z")

</div>

@markenwirt, @mdoroci

My requirement was to save the custom field at the time of registration&nbsp;

I did the following

In&nbsp;src/Resources/views/storefront/component/account/register.html.twig

```
{% sw_extends '@Storefront/storefront/component/account/register.html.twig' %}

{% block component_account_register_privacy %}
    {% block component_account_register_abandoned_cart_notification_control %}
    	{% if(shopware.config.AbandonedCartNotification.config.doNotAskEmailPermission==false) %}
		    
			    
			        {{ "abandonedCartNotification.register.abandonedCartNotificationCardTitle"|trans }}
			    
		        
		          {% block component_account_register_abandoned_cart_notification%}
		               
		          {% endblock %}

		          {% block component_account_register_enable_abandoned_cart_notification_label %}
		              
	        				{{ "abandonedCartNotification.register.enableAbandonedCartNotificationEmailText"|trans }}
		              
		          {% endblock %}
		        
		    
	    {% endif %}
	{% endblock %}

	{{ parent() }}
{% endblock %}

```

Created new file&nbsp;src/Subscriber/MappingRegisterCustomer.php

```
 */

namespace Hatslogic\Sw\AbandonedCartNotification\Subscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Framework\Event\DataMappingEvent;
use Shopware\Core\Checkout\Customer\CustomerEvents;

class MappingRegisterCustomer implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'addCustomField'
        ];
    }

    public function addCustomField(DataMappingEvent $event)
    {

        $inputData = $event->getInput();

        $outputData = $event->getOutput();

        $enableAbandonedCartNotificationEmail = $inputData->get('enable_abandoned_cart_notification_email', false);

        $enableAbandonedCartNotificationEmail = ($enableAbandonedCartNotificationEmail)? true : false;
    
        $outputData['customFields'] = array('enable_abandoned_cart_notification_email' => $enableAbandonedCartNotificationEmail);

        $event->setOutput($outputData);

        return true;
    }
}

```

That’s it. it will automatically save the custom field.

Custom field&nbsp;values will be availabe in the variable&nbsp;“context.customer.customFields” (in view page)

context.customer.customFields.enable\_abandoned\_cart\_notification\_email

---

<div class="post-metadata">

**Author:** ![markenwirt](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@markenwirt](https://forum.shopware.com/u/markenwirt)\
**Post date:** [24. Februar 2020 um 10:35 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/6 "2020-02-24T10:35:51Z")

</div>

Thank you for sharing your code, what saved us a lot of time!&nbsp;For&nbsp;the&nbsp;sake&nbsp;of&nbsp;completeness, you need to mention, that the subscriber needs to be added in an extended&nbsp;services.xml ([yourPlugin]/src/Resources/config/services.xml) like:&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![digitalhoch3](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@digitalhoch3](https://forum.shopware.com/u/digitalhoch3)\
**Post date:** [18. März 2020 um 15:52 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/7 "2020-03-18T15:52:37Z")

</div>

If you use&nbsp;CustomerEvents::MAPPING\_CUSTOMER\_PROFILE\_SAVE =\> ‘addCustomField’ too in&nbsp;getSubscribedEvents() the thinggi works in customer account profile save, too! Thanks for your tipps.

---

<div class="post-metadata">

**Author:** ![Babita](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Babita](https://forum.shopware.com/u/Babita)\
**Post date:** [16. Juli 2021 um 13:44 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/8 "2021-07-16T13:44:31Z")

</div>

Hello I have the same problem, but the custom fields ,i wanted to add at listing page, At backend its fine but not displaying at the storefront.

Thank you in advance

---

<div class="post-metadata">

**Author:** ![vanwittlaer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/vanwittlaer/32/8499_2.png) [@vanwittlaer](https://forum.shopware.com/u/vanwittlaer)\
**Post date:** [8. Februar 2022 um 08:57 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/9 "2022-02-08T08:57:44Z")

</div>

I know it’s late but for those coming along here, I have prepared an example plugin for this task: [https://github.com/vanWittlaer/blog-example-two](https://github.com/vanWittlaer/blog-example-two)  
Feedback welcome.

---

<div class="post-metadata">

**Author:** ![Deitron2](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@Deitron2](https://forum.shopware.com/u/Deitron2)\
**Post date:** [13. März 2023 um 14:36 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/10 "2023-03-13T14:36:46Z")

</div>

In Shopware 6.4.15 saving a custom field to a customer worked without the need for a subscriber:  
In the registration form just add a field with follwing name:  
name=“customFields[my\_custom\_field]”

---

<div class="post-metadata">

**Author:** ![SRach](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/srach/32/22678_2.png) [@SRach](https://forum.shopware.com/u/SRach)\
**Post date:** [27. Dezember 2023 um 15:56 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/11 "2023-12-27T15:56:34Z")

</div>

I’ve tried this with the customer entity and having a checkbox on the profile page but it did not work. I’ve added the input to the form as per documentation (as well as my custom field modifieable by the store api) and the value gets transmitted with the post request but unfortunately, the value does not update.

---

<div class="post-metadata">

**Author:** ![SRach](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/srach/32/22678_2.png) [@SRach](https://forum.shopware.com/u/SRach)\
**Post date:** [27. Dezember 2023 um 16:00 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/12 "2023-12-27T16:00:19Z")

</div>

Do you have an example for this?

---

<div class="post-metadata">

**Author:** ![SRach](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/srach/32/22678_2.png) [@SRach](https://forum.shopware.com/u/SRach)\
**Post date:** [28. Dezember 2023 um 10:04 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/13 "2023-12-28T10:04:13Z")

</div>

> I’ve tried this with the customer entity and having a checkbox on the profile page but it did not work. I’ve added the input to the form as per documentation (as well as my custom field modifieable by the store api) and the value gets transmitted with the post request but unfortunately, the value does not update.

This was because of a validation error the api did not communicate to me. My apologies

---

<div class="post-metadata">

**Author:** ![umran.buyuksuren](https://avatars.discourse-cdn.com/v4/letter/u/aca169/32.png) [@umran.buyuksuren](https://forum.shopware.com/u/umran.buyuksuren)\
**Post date:** [27. August 2025 um 07:53 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/14 "2025-08-27T07:53:22Z")

</div>

I have a similar problem: I created my own custom fields in the Admin backend and assigned them to orders. In the checkout, I integrated them via Twig (e.g., directly under the additional block), and the fields can be filled in there.

The problem: after completing the order, the fields are empty. When I open the order details in the Admin, I don’t see any values in the custom fields.

So far, I’ve managed to get the field values correctly attached to the order form, and they are also included in the POST /checkout/order. But Shopware does not automatically save them into order.customFields. That’s why I wrote a subscriber to catch the fields during checkout and write them into the order — but somehow it’s not working. ☹

---

<div class="post-metadata">

**Author:** ![bemy37](https://avatars.discourse-cdn.com/v4/letter/b/50afbb/32.png) [@bemy37](https://forum.shopware.com/u/bemy37)\
**Post date:** [27. August 2025 um 22:37 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/15 "2025-08-27T22:37:39Z")

</div>

You need to share your code otherwise, everyone can only guess what the problem might be. Shopware doesn’t automatically persist data from the objects customfields. You need to call the orderRepository and upsert the customfield data. Did you do that?

---

<div class="post-metadata">

**Author:** ![umran.buyuksuren](https://avatars.discourse-cdn.com/v4/letter/u/aca169/32.png) [@umran.buyuksuren](https://forum.shopware.com/u/umran.buyuksuren)\
**Post date:** [31. August 2025 um 14:57 UTC](https://forum.shopware.com/t/how-to-save-and-display-custom-field-values-from-frontend-in-shopware6/63848/18 "2025-08-31T14:57:25Z")

</div>

That’s my code:

```php
<?php declare(strict_types=1);

namespace CryptoCustomField\Storefront\Controller;

use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class EndkundeController extends StorefrontController
{
    #[Route(
        path: '/checkout/endkunde/save',
        name: 'frontend.checkout.endkunde.save',
        methods: ['POST'],
        defaults: ['_routeScope' => ['storefront'], '_csrf_protected' => false]
    )]
    public function save(Request $request): JsonResponse
    {
        error_log('[EndkundeController] entry');

        try {
            $keys = [
                'custom_endkunde_name',
                'custom_endkunde_mail',
                'custom_endkunde_strasse',
                'custom_endkunde_plz',
                'custom_endkunde_stadt',
                'custom_endkunde_walletid',
                'custom_endkunde_miningpool',
            ];

            $payload = [];
            foreach ($keys as $k) {
                $payload[$k] = (string) $request->request->get($k, '');
            }

            $session = $request->hasSession() ? $request->getSession() : null;
            if ($session) {
                $session->set('custom_endkunde', $payload);
                // optional: $session->save();

                error_log('[EndkundeController] saved to session: ' . json_encode($payload));

                return new JsonResponse(['saved' => true, 'via' => 'session']);
            }

            error_log('[EndkundeController] no session available');
            return new JsonResponse(['saved' => false, 'error' => 'no-session'], 200);
        } catch (\Throwable $e) {
            error_log('[EndkundeController] ERROR: ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine());
            return new JsonResponse(['saved' => false, 'error' => 'internal'], 500);
        }
    }
}

```

And that’s the subscriber:

```php
<?php

namespace CryptoCustomField\Subscriber;

use Shopware\Core\Checkout\Order\Event\OrderPlacedEvent;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;

class EndkundeOrderPlacedSubscriber implements EventSubscriberInterface
{
    public function __construct(
        private readonly EntityRepository $orderRepository,
        private readonly RequestStack $requestStack
    ) {}

    public static function getSubscribedEvents(): array
    {
        return [
            OrderPlacedEvent::class => 'onOrderPlaced',
        ];
    }

    public function onOrderPlaced(OrderPlacedEvent $event): void
    {
        $request = $this->requestStack->getCurrentRequest();
        if (!$request) {
            return;
        }

        $values = $request->getSession()->get('custom_endkunde');
        if (!\is_array($values) || !$values) {
            return;
        }

        $orderId = $event->getOrderId();
        $context = $event->getContext();

        $update = [
            'id' => $orderId,
            'customFields' => [
                'custom_endkunde_name' => (string)($values['custom_endkunde_name'] ?? ''),
                'custom_endkunde_mail' => (string)($values['custom_endkunde_mail'] ?? ''),
                'custom_endkunde_strasse' => (string)($values['custom_endkunde_strasse'] ?? ''),
                'custom_endkunde_plz' => (string)($values['custom_endkunde_plz'] ?? ''),
                'custom_endkunde_stadt' => (string)($values['custom_endkunde_stadt'] ?? ''),
                'custom_endkunde_walletid' => (string)($values['custom_endkunde_walletid'] ?? ''),
                'custom_endkunde_miningpool' => (string)($values['custom_endkunde_miningpool'] ?? ''),
            ],
        ];

        $this->orderRepository->update([$update], $context);
        $request->getSession()->remove('custom_endkunde');
    }
}

```

The POST request is sent (visible in the network tab), but the server returns HTTP 500. My troubleshooting hasn’t produced any leads so far. I suspect the event subscriber is crashing. Any ideas what might be causing this?
