Hello,
I want to insert data from form1 (I called it createFactCmd.php) then when I submit I want to pass to form2 (I called it _form.php) to insert its data also.
I have 3 models, one controller and 2 views as bellow:
[u][b]The models: [/b][/u]
I have Commande.php , Facture.php , Bien.php
[u][b]The views: [/b][/u]
I have createFactCmd.php , _form.php
[u][b] The controller action: [/b][/u]
public function actionAcquisition(){
$cmd = new Commande;
$fact = new Facture;
$model = new Bien;
if ((($cmd->load(Yii::$app->request->post()) && $cmd->validate())) && (($fact->load(Yii::$app->request->post()) && $fact->validate())) ) {
$cmd->save();
$fact->save();
$model->numfacture = $fact->numfacture;
$model->numcmd = $cmd->numcmd;
return $this->render('_form', [
'model' => $model,
]);
}
else if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->save();
}
else {
return $this->render('createFactCmd', [
'fact' => $fact,
'cmd' => $cmd,
]);
}
}
[u][b]The views: [/b][/u]
[b]The createFactCmd code: [/b]
<div class="bien-createFactCmd">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($fact, ‘numfacture’)->textInput()->label(‘Numéro facture’) ?>
<?= $form->field($fact, 'regcomm')->textInput()->label('Code fournisseur') ?>
<?= $form->field($fact, 'datefact')->textInput()->label('Date facture') ?>
<?= $form->field($fact, 'tva')->textInput()->label('TVA: ') ?>
<?= $form->field($cmd, ‘numcmd’)->textInput()->label(‘Numéro commande’) ?>
<?= $form->field($cmd, ‘datecmd’)->textInput()->label(‘Date commande:’) ?>
<div class="form-group">
<?= Html::submitButton( 'Valider', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
The _form code:
<div class="bien-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'codebien')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'codesousfamille')->textInput() ?>
<?= $form->field($model, 'typebien')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'designationbien')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'dateacquisition')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'statutbien')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'etatbien')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'prixachat')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'tauxamort')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'typeamort')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'dureevie')->textInput() ?>
<?= $form->field($model, 'commentaire')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'poids')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'garantie')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'datedebugarantie')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton( 'Enregistrer bien', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
[b][color="#FF0000"]I want to display createFactCmd form and insert its data then when I submit I want to display _form form and insert its data. My problem is that I can display createFactCmd first, I insert its data, I pass to _form but when I submit, I cant insert its data, the browser takes me back to createFactCmd.
[/color]
Can you help me plz.[/b]