当前位置: 首页>>代码示例>>PHP>>正文


PHP YDForm::addCompareRule方法代码示例

本文整理汇总了PHP中YDForm::addCompareRule方法的典型用法代码示例。如果您正苦于以下问题:PHP YDForm::addCompareRule方法的具体用法?PHP YDForm::addCompareRule怎么用?PHP YDForm::addCompareRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YDForm的用法示例。


在下文中一共展示了YDForm::addCompareRule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionDefault

 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1', 'GET', '', '_self', array('class' => 'myform'));
     // Add elements
     $form->addElement('text', 'txt1', 'Enter text 1:');
     $form->addElement('text', 'txt2', 'Enter text 2:');
     $form->addElement('submit', 'cmdSubmit', 'submit');
     $form->addRule('txt1', 'required', 'txt1 is required');
     $form->addRule('txt1', 'maxlength', 'txt1 must be smaller than 15', 15);
     $form->addCompareRule(array('txt1', 'txt2'), 'equal', 'txt1 and txt2 must be equal');
     $form->addFormRule('formrule1');
     $form->addFormRule(array('YDValidateRule', 'formrule2'));
     $form->addFilter('txt1', 'trim');
     $form->addFilter('txt2', 'trim');
     // Convert the form to XML
     $xml = $form->render('xml');
     YDDebugUtil::dump($xml, 'Form as XML data');
     //YDDebugUtil::dump( $form );
     // Recreate a new form from the XML data
     $form2 = new YDForm('form1');
     $form2->import('xml', $xml);
     //YDDebugUtil::dump( $form2 );
     YDDebugUtil::dump(array_diff_assoc($form->toArray(), $form2->toArray()), 'toArray difference');
     YDDebugUtil::dump(array_diff_assoc($form->_attributes, $form2->_attributes), '_attributes difference');
     YDDebugUtil::dump(array_diff_assoc($form->_elements, $form2->_elements), '_elements difference');
     YDDebugUtil::dump(array_diff_assoc($form->_rules, $form2->_rules), '_rules difference');
     YDDebugUtil::dump(array_diff_assoc($form->_filters, $form2->_filters), '_filters difference');
     YDDebugUtil::dump(array_diff_assoc($form->_comparerules, $form2->_comparerules), '_comparerules difference');
     YDDebugUtil::dump(array_diff_assoc($form->_formrules, $form2->_formrules), '_formrules difference');
     YDDebugUtil::dump(array_diff_assoc($form->_regElements, $form2->_regElements), '_regElements difference');
     YDDebugUtil::dump(array_diff_assoc($form->_regRules, $form2->_regRules), '_regRules difference');
     YDDebugUtil::dump(array_diff_assoc($form->_regFilters, $form2->_regFilters), '_regFilters difference');
     YDDebugUtil::dump(array_diff_assoc($form->_regRenderers, $form2->_regRenderers), '_regRenderers difference');
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:35,代码来源:form_xml2.php

示例2: actionDefault

 function actionDefault()
 {
     // Create the form
     echo '<p><b>Compare rule: equal</b></p>';
     $form1 = new YDForm('form_equal');
     $form1->addElement('text', 'txt1', 'Enter text 1:');
     $form1->addElement('text', 'txt2', 'Enter text 2:');
     $form1->addElement('text', 'txt3', 'Enter text 3:');
     $form1->addElement('submit', 'cmd1', 'equal');
     // Add the rules
     $form1->addRule('txt1', 'numeric', 'txt1 should be numeric');
     $form1->addRule('txt2', 'numeric', 'txt2 should be numeric');
     $form1->addRule('txt3', 'numeric', 'txt2 should be numeric');
     $form1->addCompareRule(array('txt1', 'txt2', 'txt3'), 'equal', 'txt1, txt2 and txt3 should be equal');
     // Validate or show the form
     if ($form1->validate()) {
         YDDebugUtil::dump($form1->getValues(), 'Form1 values');
     } else {
         $form1->display();
     }
     // Create the form
     echo '<p><b>Compare rule: asc</b></p>';
     $form2 = new YDForm('form_asc');
     $form2->addElement('text', 'txt1', 'Enter text 1:');
     $form2->addElement('text', 'txt2', 'Enter text 2:');
     $form2->addElement('text', 'txt3', 'Enter text 3:');
     $form2->addElement('submit', 'cmd1', 'asc');
     // Add the rules
     $form2->addRule('txt1', 'numeric', 'txt1 should be numeric');
     $form2->addRule('txt2', 'numeric', 'txt2 should be numeric');
     $form2->addRule('txt3', 'numeric', 'txt2 should be numeric');
     $form2->addCompareRule(array('txt1', 'txt2', 'txt3'), 'asc', 'txt1 < txt2 < txt3');
     // Validate or show the form
     if ($form2->validate()) {
         YDDebugUtil::dump($form2->getValues(), 'Form2 values');
     } else {
         $form2->display();
     }
     // Create the form
     echo '<p><b>Compare rule: desc</b></p>';
     $form3 = new YDForm('form_desc');
     $form3->addElement('text', 'txt1', 'Enter text 1:');
     $form3->addElement('text', 'txt2', 'Enter text 2:');
     $form3->addElement('text', 'txt3', 'Enter text 3:');
     $form3->addElement('submit', 'cmd1', 'desc');
     // Add the rules
     $form3->addRule('txt1', 'numeric', 'txt1 should be numeric');
     $form3->addRule('txt2', 'numeric', 'txt2 should be numeric');
     $form3->addRule('txt3', 'numeric', 'txt2 should be numeric');
     $form3->addCompareRule(array('txt1', 'txt2', 'txt3'), 'desc', 'txt1 > txt2 > txt3');
     // Validate or show the form
     if ($form3->validate()) {
         YDDebugUtil::dump($form3->getValues(), 'Form3 values');
     } else {
         $form3->display();
     }
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:57,代码来源:form_compare.php


注:本文中的YDForm::addCompareRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。