# Additional field from module in user\_billing template not inserting in database

**URL:** <https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230>\
**Category:** English forums\
**Tags:** oxid6, module, development, dev-talk\
**Created:** [February 4, 2020, 10:55am UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230 "2020-02-04T10:55:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohsin\_Javaid](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/mohsin_javaid/32/1406_2.png) [@Mohsin\_Javaid](https://forum.oxid-esales.com/u/Mohsin_Javaid)\
**Post date:** [February 4, 2020, 10:55am UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230/1 "2020-02-04T10:55:19Z")

</div>

Hello everyone!

I have a module that creates some additional text fields under user\_billing.tpl form and also an additional field for user overview under admin panel

The problem is when I go to my account and change billing address form, and add some value in that field it doesn’t get saved in the database.

But when I go to:

`vendor/oxid-esale/oxidshop-ce/source/Application/Model/User/UserUpdatabaleFields.php`

and add the column name in the array under function public function getUpdatableFields() and then goes to save the form with some value, then it updates.

So… is there something missing in a module or any leads?

Oxide shop version: 6.1.5

---

<div class="post-metadata">

**Author:** ![tabsl](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/tabsl/32/2468_2.png) [@tabsl](https://forum.oxid-esales.com/u/tabsl)\
**Post date:** [February 4, 2020, 11:22am UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230/2 "2020-02-04T11:22:53Z")

</div>

> [@Mohsin\_Javaid](#):
>
> I have a module that creates some additional text fields under user\_billing.tpl form and also an additional field for user overview under admin panel

Can you post some example code?

---

<div class="post-metadata">

**Author:** ![Mohsin\_Javaid](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/mohsin_javaid/32/1406_2.png) [@Mohsin\_Javaid](https://forum.oxid-esales.com/u/Mohsin_Javaid)\
**Post date:** [February 4, 2020, 11:34am UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230/3 "2020-02-04T11:34:08Z")

</div>

> [@tabsl](#):
>
> Can you post some example code?

i just added the template block in the ` **user_billing.tpl** `

```
<li [{if $aErrors.oxuser__asigneori}]class="oxInValid"[{/if}]>
  <label [{if $oView->isFieldRequired(oxuser__asigneori) }]class="req"[{else}]class="form_userbill" 
[{/if}]>[{ oxmultilang ident="EORI_FIELD" suffix="COLON" }]
  </label>

  <input class="textbox" [{if $oView->isFieldRequired(oxuser__asigneori) }]class="textbox js-oxValidate js-oxValidate_notEmpty" [{/if}]type="text" maxlength="255" name="invadr[oxuser__asigneori]" value="[{if isset( $invadr.oxuser__asigneori ) }][{ $invadr.oxuser__asigneori }][{else }][{ $oxcmp_user->oxuser__asigneori->value }][{/if}]">

  [{if $oView->isFieldRequired(oxuser__asigneori)}]

  <p class="oxValidateError message_invalid [{if $oView->getClassName() == 'oxwservicemenu'}]od_popupreg[{/if}]">
<span class="js-oxError_notEmpty validate_error_bill">[{ oxmultilang ident="ERROR_MESSAGE_INPUT_NOTALLFIELDS" }]
</span>
   [{include file="message/inputvalidation.tpl" aErrors=$aErrors.oxuser__asigneori}]
  </p>

  [{/if}]
      <a class="eori_info" title="[{oxifcontent ident='eori_info' object='oCont'}]
                          [{$oCont->oxcontents__oxcontent->value}]
                          [{/oxifcontent}]">
        <img src="[{$oViewConf->getImageUrl('info_icon.png')}]">
      </a>
</li>
[{oxscript add="
       $('.eori_info').tooltip();
     "}]
[{$smarty.block.parent}]

```

And this is my metadata.php file

```
 'blocks' => [
    [
        'template' => 'form/fieldset/user_billing.tpl',
        'block' => 'form_user_billing_country',
        'file' => '/views/blocks/addfields_user_billing.tpl'
    ]
]

```

---

<div class="post-metadata">

**Author:** ![Mohsin\_Javaid](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/mohsin_javaid/32/1406_2.png) [@Mohsin\_Javaid](https://forum.oxid-esales.com/u/Mohsin_Javaid)\
**Post date:** [February 5, 2020, 9:51am UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230/4 "2020-02-05T09:51:44Z")

</div>

Any leads? The additional field creatd in user\_billing.tpl doesn’t get updated, but when i go to the user from admin panel and updates that field from input field, it gets update.

I am not also getting any errors in log, so that’s why i am bit confused.

---

<div class="post-metadata">

**Author:** ![Mohsin\_Javaid](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/mohsin_javaid/32/1406_2.png) [@Mohsin\_Javaid](https://forum.oxid-esales.com/u/Mohsin_Javaid)\
**Post date:** [February 5, 2020, 12:01pm UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230/5 "2020-02-05T12:01:45Z")

</div>

Alright! fixed it on my own, created a model and overrided the default save() method from core user model.

Wrote parent::save() as a first line under my custom model save() method after that wrote my own logic.

Example:

```
class foo extends foo_parent
{
    protected $_sClassName = 'oxuser';

    public function __construct()
    {
        parent::__construct();

        $this->init('oxuser');
    }

    public function save()
    {
        parent::save();
        $oUser = $this->getUser();
        $id = $oUser->oxuser__oxid->value;

        $_oUserData = Registry::getConfig()->getRequestParameter('invadr');
        if ($_oUserData == NULL || $_oUserData == '') {
            $_oUserData = Registry::getConfig()->getRequestParameter('editval');
        }

        $sql = "UPDATE oxuser SET some_awesome_column = '" . $_oUserData["oxuser__some_awesome_column"] . "' WHERE oxid = '$id'";

        $db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
        $db->execute($sql);
    }
}
```

---

<div class="post-metadata">

**Author:** ![Mohsin\_Javaid](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/mohsin_javaid/32/1406_2.png) [@Mohsin\_Javaid](https://forum.oxid-esales.com/u/Mohsin_Javaid)\
**Post date:** [March 17, 2020, 5:52am UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230/6 "2020-03-17T05:52:27Z")

</div>

Just a little heads up if someone falls on to this topic.

I had a problem where some extra fields via module weren’t inserting in the database, So i extended the save() function from User’s model and implemented that under my module.

So far, it worked pretty fine when i was playing with billing address form in my accounts section after logging in. But i never checked if the regisration of new user worked fine too.

Few months later now, i checked and user registration weren’t working and the problem was the save() function i extended in my module.

Turns out, i also had to this little tweak which was missing logically before. Here it goes:

```
    public function save()
    {
        $blRet = parent::save(); // this should be taken in variable and then returned
        $oUser = $this->getUser();
        $id = $oUser->oxuser__oxid->value;

        $_oUserData = Registry::getRequest()->getRequestParameter('invadr');
        if ($_oUserData == NULL || $_oUserData == '') {
            $_oUserData = Registry::getRequest()->getRequestParameter('editval');
        }

        $sql = "UPDATE oxuser SET some_awesome_column = '" . $_oUserData["oxuser__some_awesome_column"] . "' WHERE oxid = '$id'";

        $db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
        $db->execute($sql);

        return $blRet; // returned right here
    }
```

---

<div class="post-metadata">

**Author:** ![system](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/system/32/4245_2.png) [@system](https://forum.oxid-esales.com/u/system)\
**Post date:** [March 17, 2021, 5:52am UTC](https://forum.oxid-esales.com/t/additional-field-from-module-in-user-billing-template-not-inserting-in-database/96230/7 "2021-03-17T05:52:27Z")

</div>

Closed on March 17, 2021, 5:52am UTC

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
