Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method "get" in from #3205

Closed
ponikrf opened this issue Apr 21, 2014 · 11 comments
Closed

Method "get" in from #3205

ponikrf opened this issue Apr 21, 2014 · 11 comments

Comments

@ponikrf
Copy link

ponikrf commented Apr 21, 2014

Make a test model - TestModel

<?php

namespace app\models;

use Yii;
use yii\base\Model;

class TestModel extends Model
{
        public $test_name;

        public function attributeLabels()
        {
            return[
                'test_name' => 'test_name',
            ];
        }


        public function rules()
        {
                return [
                        [['test_name'], 'safe'],
                ];
        }

}

Make a test form - TestForm:

$form = ActiveForm::begin(['method' => 'get',]);.
echo $form->field($model, 'test_name');
echo Html::submitButton('send', ['class' => 'btn btn-primary', 'name' => 'send']);
ActiveForm::end();

Make a controller action

    public function actionTest()
    {
        $model = new \app\models\TestModel();
        if ($model->load(Yii::$app->request->post())) {

        }
        return $this->render('test', [
            'model' => $model,
        ]);

    }

Send form

URI - index.php?r=site%2Ftest&TestModel%5Btest_name%5D=&send=

Send form

URI-index.php?r=site%2Ftest&TestModel%5Btest_name%5D=&send=&TestModel%5Btest_name%5D=&send=

Send form

index.php?r=site%2Ftest&TestModel%5Btest_name%5D=&send=&TestModel%5Btest_name%5D=&send=&TestModel%5Btest_name%5D=&send=

Its normally?

@samdark samdark added this to the 2.0 RC milestone Apr 21, 2014
@artemzakholodilo
Copy link

if pretty url is off, i think, its not normal.

@ponikrf
Copy link
Author

ponikrf commented Apr 21, 2014

Html if sends form many times

<input type="hidden" name="r" value="site/test">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">
<input type="hidden" name="send" value="">
<input type="hidden" name="TestModel[test_name]" value="">

@artemzakholodilo
Copy link

not normal, maybe samdark say something

@samdark
Copy link
Member

samdark commented Apr 21, 2014

It doesn't look OK to me as well.

@artemzakholodilo
Copy link

show, please, config/web.php file

@Ragazzo
Copy link
Contributor

Ragazzo commented Apr 21, 2014

i dont see what is wrong here, can you explain? actually values are encoded as needed.

@artemzakholodilo
Copy link

in my project if i dont use pretty url, uri look like this: index.php?r=site/index&id=1

@Ragazzo
Copy link
Contributor

Ragazzo commented Apr 21, 2014

it should look like this, what is wrong here ? if you are talking about that url rules in config for id than this is not a bug , i already asked @qiangxue some time ago , he said it is by design .

@qiangxue
Copy link
Member

This is expected. When the form method is "GET", Yii will extract the query parameters from the action URL into hidden fields because otherwise these parameters will get lost upon form submission. In your case, you need to configure the "action" option so that the URL does not include those parameters that will have text inputs. Unfortunately Yii cannot do this for you due to lack of information.

@artemzakholodilo
Copy link

is it critically?

@aksela-it
Copy link

This situation occurs when action is not set

<?php $form = ActiveForm::begin([ 'action' => \yii\helpers\Url::to(['site/index']), 'method' => 'GET', ]); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants