src/controllers/BaseController.php
public function actionSaveField()
    {
        $this->requirePostRequest();

        $fieldsService = Craft::$app->getFields();
        $request = Craft::$app->getRequest();
        $type = $request->getRequiredBodyParam('type');

        $field = $fieldsService->createField([
            'type'                 => $type,
            'id'                   => $request->getBodyParam('fieldId'),
            'groupId'              => $request->getRequiredBodyParam('group'),
            'name'                 => $request->getBodyParam('name'),
            'handle'               => $request->getBodyParam('handle'),
            'instructions'         => $request->getBodyParam('instructions'),
            'translationMethod'    => $request->getBodyParam('translationMethod', Field::TRANSLATION_METHOD_NONE),
            'translationKeyFormat' => $request->getBodyParam('translationKeyFormat'),
            'settings'             => $request->getBodyParam('types.' . $type),
        ]);

        if (!$fieldsService->saveField($field)) {
            return $this->asJson(['success' => false, 'error' => $field->getErrors()]);
        }

        return $this->asJson(['success' => true]);
    }
public function actionSaveField()
    {
        $this->requirePostRequest();

        $fieldsService = Craft::$app->getFields();
        $request = Craft::$app->getRequest();
        $type = $request->getRequiredBodyParam('type');

        $field = $fieldsService->createField([
            'type'                 => $type,
            'id'                   => $request->getBodyParam('fieldId'),
            'groupId'              => $request->getRequiredBodyParam('group'),
            'name'                 => $request->getBodyParam('name'),
            'handle'               => $request->getBodyParam('handle'),
            'instructions'         => $request->getBodyParam('instructions'),
            'translationMethod'    => $request->getBodyParam('translationMethod', Field::TRANSLATION_METHOD_NONE),
            'translationKeyFormat' => $request->getBodyParam('translationKeyFormat'),
            'settings'             => $request->getBodyParam('types.' . $type),
        ]);

        if (!$fieldsService->saveField($field)) {
            return $this->asJson(['success' => false, 'error' => $field->getErrors()]);
        }

        return $this->asJson(['success' => true]);
    }
public function actionSaveField ( ) { $ this -> requirePostRequest ( ) ; $ fieldsService = Craft :: $ app -> getFields ( ) ; $ request = Craft :: $ app -> getRequest ( ) ; $ type = $ request -> getRequiredBodyParam ( 'type' ) ; $ field = $ fieldsService -> createField ( [ 'type' => $ type , 'id' => $ request -> getBodyParam ( 'fieldId' ) , 'groupId' => $ request -> getRequiredBodyParam ( 'group' ) , 'name' => $ request -> getBodyParam ( 'name' ) , 'handle' => $ request -> getBodyParam ( 'handle' ) , 'instructions' => $ request -> getBodyParam ( 'instructions' ) , 'translationMethod' => $ request -> getBodyParam ( 'translationMethod' , Field :: TRANSLATION_METHOD_NONE ) , 'translationKeyFormat' => $ request -> getBodyParam ( 'translationKeyFormat' ) , 'settings' => $ request -> getBodyParam ( 'types.' . $ type ) , ] ) ; if ( ! $ fieldsService -> saveField ( $ field ) ) { return $ this -> asJson ( [ 'success' => false , 'error' => $ field -> getErrors ( ) ] ) ; } return $ this -> asJson ( [ 'success' => true ] ) ; }
From Craft's native saveField, which doesn't really support Ajax...
From Craft s native saveField which doesn t really support Ajax ...