# Panel language session problem

**URL:** <https://forum.getkirby.com/t/panel-language-session-problem/4959>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 12, 2016, 9:41am UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959 "2016-08-12T09:41:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 12, 2016, 9:41am UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/1 "2016-08-12T09:41:25Z")

</div>

This is a really disturbing problem. Sometimes when I add a new field the data is not saved and the language is switched back to the default one.

Today it was my Boiler field. I removed stuff to see where the problem was and it’s in the `element` function. If I remove it, it works again.

**This is my short code, a field (not a plugin) that causes the problem:**

```auto
<?php
class BoilerField extends BaseField {
	static public $fieldname = 'boiler';

	//When this is removed the problem disapears
	public function element() {
		$element = parent::element();
		$element->data('field', self::$fieldname); // SEEMS TO BE THIS LINE
		return $element;
	}
}

```

**Blueprint**

```auto
fields:
  test:
    label: Boiler
    type: boiler

```

If I rename the fieldname everywhere to `some_other_name` the problem disapears. Logout and login again did not fix the problem.

**So:**

- The problem only appears if the name everywhere is `boiler`.
- The problem only appears when I have the `element` function.

My guess is that you would not get any errors at all? That’s my experience of sessions. Really hard to solve.

## Update

After more digging it seems to be this row:

```auto
$element->data('field', self::$fieldname);

```

I still don’t get it. How can this row change my sessions?

The problem remains if I keep it but change it like this:

```auto
$element->data('field', 'boiler');

```

## Update 2

I added an animated gif. I `var_dump` the brick object in the `element` method.

1. First I show when I comment (remove) the dangerous line of code. I save in both languages.
2. Then I show when I uncomment (activate) the dangerous line of code. When I save in `de` the panel swiches back to `en`.

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/5/5d633a3365324d2fda73adc3d6042e3a3dbb5a2f.gif)

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 12, 2016, 10:38am UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/2 "2016-08-12T10:38:14Z")

</div>

I found it! 🙂

It did not had anything to do with this field at all.

Javascript from another field that was not in the blueprint caused it. I forgot to change the fieldname.

```auto
(function($) {
	$.fn.myfield= function() {
		return this.each(function() {
			var field = $(this);
			var fieldname = 'myfield';

```

So a field which is not in use, but contains javascript can screw up the language so that the page is not saved or overwritten by another language. It feels quite fragile.

Would it be possible to have the language in the panel less sensitive @lukasbestle and not so depending of the fields? Maybe it would be safer to use get variables only?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [August 12, 2016, 10:53am UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/3 "2016-08-12T10:53:50Z")

</div>

I’m not really a Panel dev. 🙈  
@bastianallgeier?

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 12, 2016, 11:18am UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/4 "2016-08-12T11:18:19Z")

</div>

@lukasbestle Ahh, I see. You fix broken stuff and minor things and @bastianallgeier create the new big things?

I tested even more because I still got issues in some cases and I found out that the problem accur when I use an incorrect ajax route.

Ajax visit a page and in this case it was leading to an error page. I guess that’s why it switches to the default language.

```nohighlight
http://localhost/kirby/panel/pages/some_field/field/undefined/boiler/ajax/

```

Anyway, I hope there is a way in the future to make more stable when it comes to keeping the chosen language. 🙂

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [August 12, 2016, 11:29am UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/5 "2016-08-12T11:29:52Z")

</div>

I do create new features, but in Kirby and the Toolkit. 🙂

---

<div class="post-metadata">

**Author:** ![martinthiemann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/martinthiemann/32/1981_2.png) [@martinthiemann](https://forum.getkirby.com/u/martinthiemann)\
**Post date:** [November 24, 2016, 7:06pm UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/6 "2016-11-24T19:06:37Z")

</div>

@jenstornell Hi Jens,  
what do you mean by “So a field which is not in use, but contains javascript can screw up the language so that the page is not saved or overwritten by another language. It feels quite fragile.”?  
We experience this “wrong language overwrite” bug a lot and it frustrates editors. I wonder now, if I can change sth in the template or blueprint to avoid this issue.  
Thanks! Martin

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [November 25, 2016, 7:22am UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/7 "2016-11-25T07:22:02Z")

</div>

Hi Martin!

I’m not sure how to get around it. I have a few plugins that suffer from it, often with ajax calls but not always.

About a month ago I added an issue about it: [https://github.com/getkirby/panel/issues/943](https://github.com/getkirby/panel/issues/943)

It’s set for milestone 2.5 so hopefully we will see a fix in that version, but milestones can change.

---

<div class="post-metadata">

**Author:** ![martinthiemann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/martinthiemann/32/1981_2.png) [@martinthiemann](https://forum.getkirby.com/u/martinthiemann)\
**Post date:** [November 25, 2016, 5:19pm UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/8 "2016-11-25T17:19:59Z")

</div>

Thanks for your reply!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:54pm UTC](https://forum.getkirby.com/t/panel-language-session-problem/4959/9 "2025-02-06T16:54:42Z")

</div>

Archived on February 6, 2025, 4:54pm UTC


