• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            xiaoguozi's Blog
            Pay it forword - 我并不覺的自豪,我所嘗試的事情都失敗了······習(xí)慣原本生活的人不容易改變,就算現(xiàn)狀很糟,他們也很難改變,在過程中,他們還是放棄了······他們一放棄,大家就都是輸家······讓愛傳出去,很困難,也無法預(yù)料,人們需要更細(xì)心的觀察別人,要隨時(shí)注意才能保護(hù)別人,因?yàn)樗麄兾幢刂雷约阂裁础ぁぁぁぁ?/span>

            Yii supports AJAX form validation, which essentially posts the form values to the server, validates them, and sends back the validation errors, all without leaving the page. It does this every time you tab out of a (changed) field.

            As of 1.1.7, Yii supports regular Javascript validation in addition to AJAX validation, but I'll talk about that in another post.

            Here's how Yii's AJAX validation works:

            1. in your yii form declaration, put:
              <php $form = $this->beginWidget('CActiveForm', array(
              'id'=>'lowercasemodelname-form', //not technically required but works w gii generated controllers
              'enableAjaxValidation'=>true //turn on ajax validation on the client side )); 
              And have at least one form element with a matching error function:
              <?php echo $form->textField($model, 'my_attribute'); ?>
              <?php echo $form->error($model, 'my_attribute'); ?> 
              This makes Yii include the JQuery javascript library, as well as a Yii javascript file called jquery.yiiactiveform.js
            2. In your controller, in create or update, after you load the model, but before you load it from POST, call this
              if(Yii::app()->getRequest()->getIsAjaxRequest()) {
              echo CActiveForm::validate( array( $model)); 
              Yii::app()->end(); 
              } 
              Which is sligtly different than how Gii generates it, but no big diff. CActiveForm::validate() can take an array of models, which is not clear the way Gii does it.
            3. Also make sure that your model has at lease one validation rule for the insert or update scenario. After you tab out of a changed field, Yii sends a standard AJAX POST to the server, and gets back a JSON response like this:
              {"Field_id":["Validation error a"],"Another_field_id":["Validation error B"]} 
              which yii then plugs into the error field below your field.
            4. When you use the $form->error() function, Yii adds a hidden div after your form element:
              <div id="Model_attributename_em_" class="errorMessage" style="display:none"></div>
              If that field has a validation error, then Yii sets the display to block, writes the validation error message to its innerHtml, and then you see the error. If it later validates, yii hides it again.
            5. Yii will also add class names to the parent container of the field that it's validating. In most cases, this is a <div class="row">. When a form field is valid, it adds "success" class to the div - which makes it green. When it's invalid, it adds "error" class, which makes it red. It also quickly adds a "validating" class, which does nothing, but you can supply it yourself and change the look of a field while it's validating.
            轉(zhuǎn)自:http://learnyii.blogspot.tw/2010/12/yii.html
            posted on 2012-12-26 12:45 小果子 閱讀(542) 評論(0)  編輯 收藏 引用 所屬分類: 學(xué)習(xí)筆記框架
            77777亚洲午夜久久多喷| 国产精品欧美久久久天天影视| 99久久亚洲综合精品网站| 狠狠色综合网站久久久久久久| 四虎国产精品免费久久5151| 久久99精品久久久久久噜噜 | 色妞色综合久久夜夜| 国产成人精品久久免费动漫| 久久久久香蕉视频| 久久精品国产秦先生| 国产精品久久久香蕉| 久久这里只有精品视频99| 久久夜色精品国产网站| 欧美性大战久久久久久| 精品国产乱码久久久久久浪潮| 久久精品国产亚洲AV嫖农村妇女| 久久精品国产亚洲精品| 久久综合视频网站| 欧美激情精品久久久久久久| 亚洲国产小视频精品久久久三级| 97精品伊人久久久大香线蕉| 久久久青草久久久青草| 国产综合久久久久久鬼色| 精品国产乱码久久久久久郑州公司| 一本久久综合亚洲鲁鲁五月天| 久久久久亚洲AV综合波多野结衣 | 久久青青草原精品国产软件| 久久久久久国产精品美女| 少妇无套内谢久久久久| 亚洲第一极品精品无码久久| 亚洲狠狠综合久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久久91精品国产一区二区三区| 久久久久免费精品国产| 久久天天躁夜夜躁狠狠| 97热久久免费频精品99| 蜜桃麻豆WWW久久囤产精品| 1000部精品久久久久久久久| 人妻精品久久久久中文字幕| 久久久久久狠狠丁香| 久久久久久亚洲Av无码精品专口|