[英]Yii2 Submiting form starts downloading view file
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
我在名为
bestellungadmin.php
的页面上有一个简单的yii2
表单,如果我单击“提交”按钮,则数据未提交,它将开始下载名为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>";
}
?>
Remove the enctype from the form options. 从表单选项中删除enctype。 (You don't need to specify any enctype options - Yii will use the default).
(您无需指定任何enctype选项-Yii将使用默认值)。
Multiform is used for uploads, hence your issue. Multiform用于上传,因此是您的问题。
Other comments: Your action clearly uses the variable $ID, so this should be specified in the function as follows: 其他注释:您的操作显然使用了变量$ ID,因此应在函数中指定如下:
public function actionBestelling($id = null){
Doing this will automatically populate $id for you making it easier to code. 这样做将自动为您填充$ id,从而使编码更容易。
$row can be re-written as: $ row可以重写为:
$row = Bestellung::findAll([‘id’=>$id]);
This presumes that there are multiple rows with the same ID... which is odd. 假设有多个具有相同ID的行……这很奇怪。 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. 如果确实只有一个ID,那么您也可以在视图文件中删除foreach语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.