• <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 - 我并不覺的自豪,我所嘗試的事情都失敗了······習慣原本生活的人不容易改變,就算現狀很糟,他們也很難改變,在過程中,他們還是放棄了······他們一放棄,大家就都是輸家······讓愛傳出去,很困難,也無法預料,人們需要更細心的觀察別人,要隨時注意才能保護別人,因為他們未必知道自己要什么·····

            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.
            轉自:http://learnyii.blogspot.tw/2010/12/yii.html
            posted on 2012-12-26 12:45 小果子 閱讀(546) 評論(0)  編輯 收藏 引用 所屬分類: 學習筆記框架
            久久毛片免费看一区二区三区| 久久精品国产亚洲αv忘忧草| 成人a毛片久久免费播放| 亚洲国产成人久久一区WWW| 69久久夜色精品国产69| 一本一本久久a久久综合精品蜜桃| 国产激情久久久久影院老熟女免费| 久久精品国产一区二区三区| 26uuu久久五月天| 久久精品国产半推半就| 久久91精品国产91久久小草| 伊人久久大香线蕉AV一区二区| 国产人久久人人人人爽| 国产精品免费福利久久| 久久综合给合综合久久| 婷婷综合久久中文字幕| 精品乱码久久久久久久| 精品国产99久久久久久麻豆| 久久高潮一级毛片免费| 久久九九免费高清视频 | 超级碰久久免费公开视频| 久久精品人人做人人爽电影| 欧美日韩成人精品久久久免费看| 久久久久99精品成人片牛牛影视| 久久精品国产亚洲av日韩| 国产精品久久久久AV福利动漫| 青青草原综合久久大伊人| 九九久久自然熟的香蕉图片| 国产精品久久久久久久人人看| 欧美麻豆久久久久久中文| 精品久久久久久久中文字幕| a级毛片无码兔费真人久久| 国产高潮久久免费观看| 久久99精品久久久久久水蜜桃| 国产精品狼人久久久久影院| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区| 日产精品久久久久久久性色| 久久亚洲色一区二区三区| 欧美精品福利视频一区二区三区久久久精品 | 欧美日韩久久中文字幕| 国产精品欧美亚洲韩国日本久久|