Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Yii2 如何在不使用提交按钮的情况下从多个下拉列表中获取数据_Yii2 - Fatal编程技术网

Yii2 如何在不使用提交按钮的情况下从多个下拉列表中获取数据

Yii2 如何在不使用提交按钮的情况下从多个下拉列表中获取数据,yii2,Yii2,嗨,这是我的控制器 public function actionCreate() { $this->layout = "main"; $location = \Yii::$app->getRequest()->getCookies()->getValue( 'location_id' ); if ( $location != NULL ) {

嗨,这是我的控制器

 public function actionCreate()
        {
            $this->layout = "main";
            $location     = \Yii::$app->getRequest()->getCookies()->getValue( 'location_id' );

        if ( $location != NULL )
        {
            $model = new ScreenTicketBooking();
            if ( $model->load( Yii::$app->request->post() ) )
            {
                return $this->redirect( [ 'time', 'ids' => $model->show_date, 'id' => $model->movie_id ] );
            }
            else
            {
                return $this->render( 'create', [
                    'model' => $model,
                ] );
            }
        }
        else
        {
            return $this->redirect( [ 'site/home' ] );
        }
    }
这是我的看法

 <?php

        use app\models\Locations;
        use app\models\Movies;
        use app\models\MovieShows;
        use app\models\ScreenClasses;
        use app\models\ScreenClassSeats;
        use app\models\Screens;
        use app\models\ScreenShowTimes;
        use app\models\Theatres;
        use yii\helpers\ArrayHelper;
        use yii\helpers\Html;
        use yii\helpers\Url;
        use yii\widgets\ActiveForm;

        /* @var $this yii\web\View */
        /* @var $model app\models\ScreenTicketBooking */
        /* @var $form yii\widgets\ActiveForm */
    ?>

    <div class="screen-ticket-booking-form col-md-4">

        <?php $form = ActiveForm::begin(); ?>

        <?php

            $location = \Yii::$app->getRequest()->getCookies()->getValue( 'location_id' );

            $movies = MovieShows::find()->where( [ 'location_id' => $location ] )->andWhere( [ '>', 'end_date',
                                                                                               date( 'Y-m-d' ) ] )->all();

            if ( $movies != NULL )
            {
                foreach ( $movies as $movie )
                {
                    $dataCategory[ ] = ArrayHelper::map( Movies::find()->where( 'status=:stat', [ 'stat' => 0 ] )
                                                               ->andWhere( [ 'id' => $movie->movie_id ] )->all(), 'id',
                        'movie_name' );
                }
            }
            else
            {
                $dataCategory = NULL;
            }

            $newArray = [ ];
            if ( $movies != NULL )
            {
                foreach ( $dataCategory as $array )
                {
                    foreach ( $array as $k => $v )
                    {
                        $newArray[ $k ] = $v;
                    }
                }
            }


            echo $form->field( $model, 'movie_id' )->dropDownList( $newArray,
                [ 'prompt'   => '-Choose a Movie-',
                  'onchange' => '
                                               $.get( "' . Url::toRoute( 'screenticketbooking/dependdrop' ) . '", { id: $(this).val() } )
                                .done(function( data )
                       {
                                  $( "select#title" ).html( data );
                                });
                            ' ] )->label( '' ); ?>

        <?php $dataPost = ArrayHelper::map( MovieShows::find()
                                                      ->where( 'movie_id=:mov_id', [ 'mov_id' => $model->movie_id ] )
                                                      ->asArray()->all(), 'id', 'start_date' );
            echo $T = $form->field( $model, 'show_date' )
                           ->dropDownList(
                               $dataPost,
                               [ 'id' => 'title', 'prompt' => '-Select a Date-' ]
                           )->label( '' );

        ?>

        <div class="form-group">

            <?= 
            Html::submitButton( $model->isNewRecord ? Yii::t( 'app', 'OK' ) : Yii::t( 'app', 'Update' ),
                [ 'name' => 'submit', 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary',
                  'id'   => 'ajith' ] ) ?>


        </div>

        <?php ActiveForm::end(); ?>

    </div>
两者都工作完美,但现在我不想使用提交按钮,当两个下拉菜单都被选中,然后自动重定向到行动时间。我使用的是双向相关下拉列表。我怎样才能做到这一点呢?

试试这个

<?php $dataPost = ArrayHelper::map( MovieShows::find()
                                                      ->where( 'movie_id=:mov_id', [ 'mov_id' => $model->movie_id ] )
                                                      ->asArray()->all(), 'id', 'start_date' );
            echo $T = $form->field( $model, 'show_date' )
                           ->dropDownList(
                               $dataPost,
                               [ 'id' => 'title', 'prompt' => '-Select a Date-', 'onchange' => 'this.form.submit()' ]
                           )->label( '' );

        ?>
在提交表单后选择“显示日期”时使用此选项