Yii implements multiple button saving and submission methods, and yii implements button submission

Source: Internet
Author: User

Yii implements multiple button saving and submission methods, and yii implements button submission

This example describes how to save and submit multiple buttons in Yii without conflict. 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:
Copy codeThe 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 codeThe 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:
Copy codeThe Code is as follows: <input type = "submit" name = "submityes" value = <? Php echo Yii: t ('common', "Submit")?>
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.