This article mainly introduces how Yii can save and submit multiple buttons without conflict. it is a very practical technique in form production, for more information about how to save and submit multiple buttons in Yii, see the example in this article. This is a problem that many beginners have encountered but do not know how to solve. I will share it with you for your reference. The specific method is as follows:
In Yii, only CForm can use the submitted () method. if ($ form-> submitted ('submit ') is used to determine whether the button with buttonName as submit is clicked. for example:
Form:
The code is as follows:
'Buttons' => array (
'Preview' => array (
'Type' => 'Submit ',
'Label' => yii: t ('core', 'show preview '),
),
'Draft '=> array (
'Type' => 'Submit ',
'Label' => yii: t ('core', 'Save draft '),
),
'Submit '=> array (
'Type' => 'Submit ',
'Label' => yii: t ('core', 'submit '),
),
CHtml: link (yii: t ('core', 'cancel'), yii: app ()-> homeUrl ),
),
Controller:
The code is as follows:
If ($ form-> submitted ('submit '))
$ Model-> status = Post: STATUS_PROPOSED;
Else
$ Model-> status = Post: STATUS_DRAFT;
However, CActiveForm does not use this method. a solution is to use classical html:
The code is as follows:
>
If (isset ($ _ POST ['submityes'])
That's all.
Shows the final running effect:
I hope this article will help you design PHP programs based on the Yii Framework.