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>";
}
?>
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.