duannai5858 2019-08-05 13:22
浏览 109

Yii2提交表单开始下载视图文件

I have a simple yii2 form on a page called bestellungadmin.php If i click the submit button, the data does not submitted, it starts downloading a file named bestellungadmin

The browser console prints the message:

jquery.js?v=1556869380:7841 Resource interpreted as Document but transferred with MIME type application/x-httpd-php: "https://rueckschlag.com/bestellungadmin?ID=101".

I have lots of the same forms on other sites of the project, all are working just this one not.

my controller:

public function actionBestellungadmin(){
        if(Yii::$app->user->isGuest){
            return $this->goHome();
        }else if(Yii::$app->user->identity->getAdmin()){
            $model= new Bestellung();
            $model->load(Yii::$app->request->get());
            if($model->load(Yii::$app->request->post())){
                $model->updateBestellung();
                Yii::$app->session->setFlash('success', 'Bestellung erfolgreich aktuallisiert.');
                return $this->redirect('bestellungenoffen');
            }else if(Yii::$app->request->get('ID')){

                        $ID = Yii::$app->request->get('ID');
                        $query = new Query;
                        // compose the query
                        $query->select('*')
                                ->from('bestellung')
                                ->where("ID = '$ID'");
                        // build and execute the query
                        $row = $query->all();                       
                        return $this->render('bestellungadmin', ['model'=>$model, 'output'=>$row]);
            }else{
                return $this->render('bestellungenoffen');
            }
        }else{
            return $this->goHome();
        }
    }

my form:

<?php 
                foreach($output as $row){
                    echo "<div class='row artikelAdmin'>";
                $form = ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data']]); 

                echo $form->field($model, 'Nummer')->textInput(['readonly' => true, 'value' => $row['Nummer']]);
                echo $form->field($model, 'Datum')->textInput(['readonly' => true, 'value' => $row['Datum']]);
                echo $form->field($model, 'Artikel')->textInput(['readonly' => false, 'value' => $row['Artikel']]);
                echo "<a href='".$row['Rechnung']."'>Rechnung</a>";
                echo $form->field($model, 'Anmerkung')->textArea(['readonly' => true, 'value' => $row['Anmerkung']]) ;
                echo $form->field($model, 'Email')->textInput(['readonly' => false, 'value' => $row['Email']]) ;
                echo $form->field($model, 'Adresse')->textInput(['readonly' => false, 'value' => $row['Adresse']]) ;
                echo $form->field($model, 'PreisArtikel')->textInput(['readonly' => false, 'value' => $row['PreisArtikel']]) ;
                echo $form->field($model, 'PreisGesamt')->textInput(['readonly' => false, 'value' => $row['PreisGesamt']]) ;
                echo $form->field($model, 'Status')->dropDownList(['Storniert' => 'Storniert','Warten auf Zahlungseingang'=> 'Warten auf Zahlungseingang', 'Zahlung erhalten, Versandvorbereitung' => 'Zahlung erhalten, Versandvorbereitung', 'Bestellung verschickt' => 'Bestellung verschickt'],['options'=>[$row['Status']=>['Selected'=>true]]])->label('Status Ändern');
                echo $form->field($model, 'Nachricht')->textArea(['readonly' => false]) ;
                echo "<div class='form-group'>";
                echo Html::submitButton("speichern", ['class' => 'btn btn-primary ', 'name' => 'speichern']) ;
                echo "</div>";
                ActiveForm::end(); 
                echo "</div>";
                }
                ?>
  • 写回答

1条回答 默认 最新

  • dsvtnz6350 2019-08-05 19:16
    关注

    Remove the enctype from the form options. (You don’t need to specify any enctype options - Yii will use the default).

    Multiform is used for uploads, hence your issue.

    Other comments: Your action clearly uses the variable $ID, so this should be specified in the function as follows:

    public function actionBestelling($id = null){
    

    Doing this will automatically populate $id for you making it easier to code.

    $row can be re-written as:

    $row = Bestellung::findAll([‘id’=>$id]); 
    

    This presumes that there are multiple rows with the same ID... which is odd. If that is not the case, then use:

    $row = Bestellung::findOne($id);
    

    If there is indeed only one ID, then you can also remove the foreach statement in the view file.

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题