I have two problems with pjax and maybe someone can help me. I have one pjax form which with get params reload grid view. And grid view have pjax filters which reload grid again. So my problems is:
Any ideas how to fix any of these issues?
| Q | A |
| --- | --- |
| Yii version | 2.0.8 |
Seems you do it wrong. I had this problem to but because my setup (both on widget and layout) is wrong. Please share your view code.
Here is my example:
search.zip
Tell me what I am doing wrong.
@DMGPage
Your code was:
<?= Html::beginForm('', 'get', ['class' => 'form-horizontal', 'id' => 'search-form', 'data-pjax' => true]); ?>
you need to specify target form-action in array [] if you want to target same as action. change to:
<?= Html::beginForm([''], 'get', ['class' => 'form-horizontal', 'id' => 'search-form', 'data-pjax' => true]); ?>
Quite weird for me observing this behavior. Becase on docs it says array|string (see here)
Why? Form will call Url:to() and from documentation: "an empty string: the currently requested URL will be returned".
And how does your suggestion fix any of my problems with pjax?
Have you try to use [''] ?
Yes, and from, what I see, it fix duplicates parameters in url. Only problem, that I can not find any explanation, why [''] have different behaviour from ''. Even returned urls are equal, but with '' pjax duplicates params and with [''] will replace.
But first pjax problem remains. It still replace empty space with +.
But first pjax problem remains. It still replace empty space with +.
Is all fields empty?
As far as I know, space will be converted to + based on URL Encoding.
http://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
On my browser, Chrome & Edge works fine.
Chrome
Edge
It is fine that space is converted to +. Problem is next time when pjax is called, because it replace + with "%2B" and now $_GET param has value "+" instead of space.
Works fine:
Consider using Yii::$app->request->getQueryParams(); instead $_GET
I think your issue now is not related by Yii code, but rather than your system environment setup / settings.
Take my code, if you wondering https://gist.github.com/agungsijawir/c6017d7c0840e1200cc3d26c9858d3eb
Yes this change everything :)
public function getQueryParams()
{
if ($this->_queryParams === null) {
return $_GET;
}
return $this->_queryParams;
}
Btw in my example I use "Yii::$app->request->get('first_name')" and result is wrong:

And from your result I see that you did only 1. step and did not searched in grid. Problem only appear after second pjax call when it takes current url and add new params.
I did not only one or two pjax call, but more than that. The result are same, works perfect.
either on form on filter on grid. same result, works as expected.
check your environment setup / config.
Please close this issue as this not related to yii code.
Wait what environment settings should I check? I did clean yii installation and I still have same problem.
What about Encoding you use on your browser, UTF-8 or what?
What your regional settings, if you use Windows(tm) OS?
php version?
yii2-pjax version?
can you use latest yii2 version, yii2 v2.0.9?
kindly submit your output phpinfo() result page.
On your dev-tools (chorme, edge, mozilla), Request & Response Headers, especially for pjax / xhr request.
Please run requirements.php in your yii2 installations.
See image below, either by + or %20, the result are same on me.
_What about Encoding you use on your browser, UTF-8 or what?_
Yes, utf-8
_What your regional settings, if you use Windows(tm) OS?_
Windows 7 - language for non-unicode programs: Latvian (Latvia)
_php version?_
info.pdf
_yii2-pjax version?_
version what comes with yii 2.0.9
_On your dev-tools (chorme, edge, mozilla), Request & Response Headers, especially for pjax / xhr request._
request.pdf
_Please run requirements.php in your yii2 installations._
requirements.pdf
_See image below, either by + or %20, the result are same on me._
In my case + is replaced with %2B and it happens in firefox and chrome. Tested even on linux mint + firefox and same problem. So it is not browser or OS problem.
Can you change your Regional Settings to US?
I did test on Firefox too, but behavior was same.
Edited:
Even on Xubuntu 14.04 using Firefox, works as expected.
Please update your Regional Settings.
Ok, make it simple to debug.
Use this simple plain php, html and jquery, jquery-pjax
I got this, what about you?
Wait you have name in form and name in grid? Of Course you will have different result. Could you test with my view file? Or at least use different names and follow steps described above.
_Can you change your Regional Settings to US?_

here, with no model. same code with yours except CGridView components.
https://github.com/yiisoft/yii2/issues/11921#issuecomment-231980458
Here #11921 you do not have grid filter result combined with form params. Your url contains only form fields and this request works for me too. But if then I enter something in grid filter, data is changed. Well everything you can see in request.pdf. There is 2 requests: 1. after form submit; 2. after grid filter.
_same code with yours except CGridView components._
Use GridView, it does not change anything. In clean yii I use GridView too, and result is same. But don't ignore this part, because my problem is only second pjax request, which comes from grid filter. Form by it self works good.
Ah, I see...
To produce this issue:
Html::beginForm() and Html::endForm(), put an input box (named it first_name) and wrap the form with pjax.this is test. Url with get params will change to this+is+test.Something field on MyModel model) with space on string field, i.e. find a thing, enter.controller/action?MyModel[Something]=find+a+thing&first_name=this%20is%20test . When dump \Yii::$app->request->get('first_name'), output will be find+a+thing.note:
\yii\base\Model for use in search form.Can you use same model as GridView on your search form?
Yes, and result not changed. Here is my test view, model and controller:
search.zip

Failed to reproduce (open GIF in new tab)
Test is performed differently than I described and @agungsijawir reproduced. From your gif I can see that you @SilverFire did not entered any text in first form. Please read accurately @agungsijawir comment how to reproduce this issue.
In short:
@DMGPage thank you for pointing out my mistake
Most helpful comment
What about Encoding you use on your browser, UTF-8 or what?
What your regional settings, if you use Windows(tm) OS?
php version?
yii2-pjax version?
can you use latest yii2 version, yii2 v2.0.9?
kindly submit your output
phpinfo()result page.On your dev-tools (chorme, edge, mozilla), Request & Response Headers, especially for pjax / xhr request.
Please run requirements.php in your yii2 installations.
See image below, either by

+or%20, the result are same on me.