How to implement multi-button saving and submission in Yii, how to implement button submission in Yii_PHP tutorial

WBOY
Release: 2016-07-13 10:12:20
Original
741 people have browsed it

Yii implements multi-button save and submit method, yii implements button submission

The example in this article describes how Yii implements multi-button save and submit without conflict. This is a problem that many beginners have encountered but don’t know how to solve. I’ll share it with you below for your reference. The specific method is as follows:

Only CForm in Yii can use the submitted() method. Use if($form->submitted('submit')) to determine whether the button whose buttonName is submit is clicked, such as:
Form:

Copy code 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:

Copy code The code is as follows:
if($form->submitted('submit'))
$model->status=Post::STATUS_PROPOSED;
else
$model->status=Post::STATUS_DRAFT;

But CActiveForm does not have this method. One solution is to use classical html writing:
Copy code The code is as follows:
>
if(isset($_POST['submityes']))

That's it.

The final running effect is shown below:

I hope this article will help you design PHP programs based on the Yii framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920978.htmlTechArticleYii implements multi-button saving and submission methods, yii implements button submission. This article describes the example of Yii implementing multi-button saving and submission. Submit and conflict-free implementation method. This is something many beginners have encountered...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template