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


PHP YDForm::addRule方法代码示例

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


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

示例1: actionDefault

 function actionDefault()
 {
     // Mark the form as not valid
     $this->template->assign('formValid', false);
     // Create the form
     $form = new YDForm('uploadForm');
     // Add the elements
     $file =& $form->addElement('file', 'file1', 'Select a file to upload:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Add a rule
     $form->addRule('file1', 'uploadedfile', 'You need to select a valid file');
     //$form->addRule( 'file1', 'maxlength', 'Path can only be 8 characters', 8 );
     $form->addRule('file1', 'maxfilesize', 'Maximum filesize of 10 KB is exceeded!', 10 * 1024);
     //$form->addRule( 'file1', 'extension', 'File extension should be txt!', 'txt' );
     // Process the form
     if ($form->validate()) {
         // Move the uploaded file
         if ($file->isUploaded()) {
             // Move the upload
             $file->moveUpload('.');
             // Mark the form as valid
             $this->template->assign('formValid', true);
         }
     }
     // Add the form to the template
     $this->template->assign('form_html', $form->toHtml());
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:30,代码来源:fileupload.php

示例2: actionAddNote

 function actionAddNote()
 {
     // Create the add form
     $form = new YDForm('addEntryForm');
     // Add the elements
     $form->addElement('text', 'title', 'Title:');
     $form->addElement('textarea', 'body', 'Contents:');
     $form->addElement('submit', 'cmdSubmit', 'Save');
     // Apply filters
     $form->addFilter('title', 'trim');
     $form->addFilter('body', 'trim');
     // Add a rule
     $form->addRule('title', 'required', 'Title is required');
     $form->addRule('body', 'required', 'Contents is required');
     // Process the form
     if ($form->validate()) {
         // Save the entries in an array
         $entry = array('id' => md5($form->getValue('title') . $form->getValue('body')), 'title' => $form->getValue('title'), 'body' => $form->getValue('body'));
         // Save the serialized entry to a file
         $this->dataDir->createFile($entry['id'] . '.dat', YDObjectUtil::serialize($entry));
         // Forward to the list view
         $this->forward('default');
         // Return
         return;
     }
     // Add the form to the template
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:30,代码来源:index.php

示例3: actionDefault

 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     $form->registerFilter('reverse', 'strrev');
     $form->setDefaults(array('txt2' => 'First text', 'txt3' => "2\nlines", 'hid1' => 'me hidden', 'chk1' => 'x', 'chk2' => false, 'sel1' => 2));
     $text =& $form->addElement('text', 'txt1', 'Enter text 1:');
     $text->_label = 'new label for txt1';
     $form->addElement('text', 'txt2', 'Enter text 2:', array('class' => 'textInputClass', 'name' => 'x'));
     $form->addElement('textarea', 'txt3', 'Enter text 2:');
     $form->addElement('textareacounter', 'txtcounter_1', 'Textarea counter 1', array(), array('maxlength' => 10, 'before' => ' (', 'after' => ' characters remaining)'));
     $form->addElement('textareacounter', 'txtcounter_2', 'Textarea counter 2');
     $form->addElement('radio', 'rad1', 'Select a value 1:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('radio', 'rad2', 'Select a value 2:', array(), array(1 => 'een<br/>', 2 => 'twee'));
     $form->addElement('hidden', 'hid1', '');
     $form->addElement('hidden', 'hid2', '', array(), 'i am also hidden');
     $form->addElement('image', 'img1', '', array(), 'http://www.scripting.com/images/xml.gif');
     $form->addElement('password', 'pas1', 'Enter your password');
     $form->addElement('bbtextarea', 'bbt1', 'Enter your BBCode');
     $form->addElement('checkbox', 'chk1', 'Select me please');
     $form->addElement('checkbox', 'chk2', 'Select me please');
     $form->addElement('select', 'sel1', 'Select an option:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('span', 'span1', 'This is a span. The next element is an image (img).');
     $form->addElement('img', 'img2', 'http://www.scripting.com/images/xml.gif');
     $form->addElement('file', 'fil1', 'Select an file:');
     $form->addElement('submit', 'cmd1', 'Send');
     $form->addElement('reset', 'res1', 'Reset');
     $form->addFilter('__ALL__', 'upper');
     $form->addFilter('txt1', 'trim');
     $form->addFilter('txt2', 'reverse');
     $form->addRule('txt1', 'required', 'txt1 is required');
     $form->addRule('chk2', 'exact', 'chk2 is required', 1);
     $form->addFormRule(array(&$this, 'formrule'), 'txt1 is required');
     if (YDConfig::get('YD_DEBUG') == 1 || YDConfig::get('YD_DEBUG') == 2) {
         YDDebugUtil::dump($form->_regElements, 'Registered elements');
         YDDebugUtil::dump($form->_regRules, 'Registered rules');
         YDDebugUtil::dump($form->_regFilters, 'Registered filters');
         YDDebugUtil::dump($form->_filters, 'Filters');
         YDDebugUtil::dump($form->_rules, 'Rules');
         YDDebugUtil::dump($form->_formrules, 'Form Rules');
         YDDebugUtil::dump($form->getValue('txt1'), 'txt1');
         YDDebugUtil::dump($form->getValue('txt2'), 'txt2');
         YDDebugUtil::dump($_POST, '$_POST');
         YDDebugUtil::dump($_FILES, '$_FILES');
         YDDebugUtil::dump($form->toArray());
     }
     if ($form->validate()) {
         YDDebugUtil::dump($form->getModifiedValues(), 'Form modified values');
         YDDebugUtil::dump($form->getValues(), 'Form values');
     } else {
         $form->display();
     }
     // Create the form
     $form2 = new YDForm('form2');
     $form2->setDefaults(array('txt1' => 'First text'));
     $form2->addElement('text', 'txt1', 'Enter text 1:');
     $form2->addElement('text', 'txt2', 'Enter text 2:');
     $form2->addElement('submit', 'cmd1', 'Send');
     $form2->display();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:60,代码来源:form2.php

示例4: 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

示例5: 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

示例6: actionDefault

 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     $form->registerFilter('reverse', 'strrev');
     $form->setDefaults(array('txt2' => 'First text', 'txt3' => "2\nlines", 'hid1' => 'me hidden', 'chk1' => 'x', 'sel1' => 2));
     $text =& $form->addElement('text', 'txt1', 'Enter text 1:');
     $text->_label = 'new label for txt1';
     $form->addElement('text', 'txt2', 'Enter text 2:', array('class' => 'textInputClass', 'name' => 'x'));
     $form->addElement('textarea', 'txt3', 'Enter text 2:');
     $form->addElement('radio', 'rad1', 'Select a value 1:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('radio', 'rad2', 'Select a value 2:', array(), array(1 => 'een<br/>', 2 => 'twee'));
     $form->addElement('hidden', 'hid1', '');
     $form->addElement('hidden', 'hid2', '', array(), 'i am also hidden');
     $form->addElement('image', 'img1', '', array(), 'http://www.yellowduck.be/images/site_images/rss091.gif');
     $form->addElement('password', 'pas1', 'Enter your password');
     $form->addElement('bbtextarea', 'bbt1', 'Enter your BBCode');
     $form->addElement('checkbox', 'chk1', 'Select me please');
     $form->addElement('checkbox', 'chk2', 'Select me please');
     $form->addElement('select', 'sel1', 'Select an option:', array(), array(1 => 'een', 2 => 'twee'));
     $form->addElement('file', 'fil1', 'Select an file:');
     $form->addElement('submit', 'cmd1', 'Send');
     $form->addElement('reset', 'res1', 'Reset');
     $form->addFilter('__ALL__', 'upper');
     $form->addFilter('txt1', 'trim');
     $form->addFilter('txt2', 'reverse');
     $form->addRule('txt1', 'required', 'txt1 is required');
     $form->addRule('chk2', 'required', 'chk2 is required');
     $form->addFormRule(array(&$this, 'formrule'), 'txt1 is required');
     if (YD_DEBUG == 1) {
         YDDebugUtil::dump($form->_regElements, 'Registered elements');
         YDDebugUtil::dump($form->_regRules, 'Registered rules');
         YDDebugUtil::dump($form->_regFilters, 'Registered filters');
         YDDebugUtil::dump($form->_filters, 'Filters');
         YDDebugUtil::dump($form->_rules, 'Rules');
         YDDebugUtil::dump($form->_formrules, 'Form Rules');
         YDDebugUtil::dump($form->getValue('txt1'), 'txt1');
         YDDebugUtil::dump($form->getValue('txt2'), 'txt2');
         YDDebugUtil::dump($_POST, '$_POST');
         YDDebugUtil::dump($_FILES, '$_FILES');
     }
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues(), 'Form values');
     } else {
         $form->display();
     }
     // Create the form
     $form2 = new YDForm('form2');
     $form2->setDefaults(array('txt1' => 'First text'));
     $form2->addElement('text', 'txt1', 'Enter text 1:');
     $form2->addElement('text', 'txt2', 'Enter text 2:');
     $form2->addElement('submit', 'cmd1', 'Send');
     $form2->display();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:54,代码来源:form2.php

示例7: actionDefault

 function actionDefault()
 {
     // Mark the form as not valid
     $this->setVar('formValid', false);
     // Create the form
     $form = new YDForm('uploadForm');
     // Add the elements
     $file =& $form->addElement('file', 'file1', 'Select a file to upload:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Add a rule
     $form->addRule('file1', 'uploadedfile', 'You need to select a valid file');
     // Process the form
     if ($form->validate()) {
         // Move the uploaded file
         if ($file->isUploaded()) {
             $file->moveUpload('.');
         }
         // Mark the form as valid
         $this->setVar('formValid', true);
     }
     // Add the form to the template
     $this->setVar('form_html', $form->toHtml());
     $this->addForm('form', $form);
     // Output the template
     $this->outputTemplate();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:26,代码来源:fileupload.php

示例8: actionDefault

 function actionDefault()
 {
     // Create the form
     $form = new YDForm('form1');
     // Add a first set of elements
     $form->addElement('date', 'date1', 'Date1', '');
     $form->addElement('date', 'date2', 'Date2 (monthabbr = true)', array('id' => 'mydate'), array('monthabbr' => true));
     $form->addElement('date', 'date3', 'Date3 (monthnumber = true)', '', array('monthnumber' => true));
     $form->addElement('date', 'date4', 'Date4 (monthucfirst = true)', '', array('monthucfirst' => true));
     $form->addElement('date', 'date5', 'Date5 (yearstart = 1970, yearend=2007, yeartwodigits = true)', '', array('yearstart' => 1970, 'yearend' => 2007, 'yeartwodigits' => true));
     $form->addElement('date', 'time1', 'Time1', '', array('time'));
     $form->addElement('date', 'time2', 'Time2 (minutesoffset = 10)', '', array('time', 'minutesoffset' => 10));
     $form->addElement('date', 'time3', 'Time3 (secondsoffset = 15)', '', array('time', 'secondsoffset' => 15));
     $form->addElement('date', 'datetime1', 'DateTime1', '', array('datetime'));
     $form->addElement('date', 'date6', 'Date6 (month, year)', '', array('month', 'year'));
     $form->addElement('date', 'date7', 'Date7 (day, month)', '', array('day', 'month'));
     $form->addElement('date', 'date8', 'Date8 (day, hours, minutes)', '', array('day', 'hours', 'minutes'));
     $form->addElement('submit', '_cmdSubmit', 'Submit');
     // Add rules
     $form->addRule(array('date1', 'date2', 'date3', 'date4', 'date5', 'time1', 'time2', 'time3', 'datetime1', 'date6', 'date7', 'date8'), 'date', 'must be a valid date');
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues(), '$form->getValues()');
     }
     // Display form
     $form->display();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:26,代码来源:form_date.php

示例9: actionDefault

 function actionDefault()
 {
     // create form
     $form = new YDForm('myform');
     // add elements
     $form->addElement('text', 'txt', 'Enter your name:');
     $form->addElement('captcha', 'cap', 'Enter code:');
     $form->addElement('submit', 'cmd', 'Send');
     // add rules
     $form->addRule('txt', 'required', 'Your name is required');
     $form->addRule('cap', 'captcha', 'Security code is not valid');
     if ($form->validate()) {
         YDDebugUtil::dump($form->getValues(), 'Form values');
     } else {
         $form->display();
     }
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:17,代码来源:form_captcha.php

示例10: actionDefault

 function actionDefault()
 {
     // Mark the form as not valid
     $this->template->assign('formValid', false);
     // Create the form
     $form = new YDForm('uploadForm');
     // Add the elements
     $file =& $form->addElement('file', 'file1', 'Select a file to upload:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Add a rule
     $form->addRule('file1', 'uploadedfile', 'You need to select a valid file');
     //$form->addRule( 'file1', 'maxlength', 'Path can only be 8 characters', 8 );
     $form->addRule('file1', 'maxfilesize', 'Maximum filesize of 1000 KB is exceeded!', 1000 * 1024);
     //$form->addRule( 'file1', 'extension', 'File extension should be txt!', 'txt' );
     // Process the form
     if ($form->validate()) {
         // Move the uploaded file
         if ($file->isUploaded()) {
             // You may fetch the name before the file hits the FS
             $temp_filename = $file->getBaseName();
             // Move the upload
             $file->moveUpload('./tmp');
             //$file->moveUpload( './tmp', 'TEST_' . $temp_filename );
             //$file->moveUpload( './tmp', md5(time()) );
             //$file->moveUpload( './tmp', md5(time()), true );
             // Mark the form as valid
             $this->template->assign('formValid', true);
             // Display file information
             $this->template->assign('filename', $file->getBaseName());
             $this->template->assign('filesize', $file->getSize());
             $this->template->assign('ext', $file->getExtension());
             $this->template->assign('path', $file->getPath());
         }
     }
     // Add the form to the template
     $this->template->assign('form_html', $form->toHtml());
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:40,代码来源:fileupload.php

示例11: actionDefault

 function actionDefault()
 {
     // Set the title of the form
     $this->template->assign('title', 'Sample form');
     // Mark the form as not valid
     $this->template->assign('formValid', false);
     // Create the form
     $form = new YDForm('firstForm');
     // Set the defaults
     $form->setDefaults(array('name' => 'Joe User'));
     // Add the elements
     $form->addElement('text', 'name', 'Enter your name:', array('size' => 50));
     $form->addElement('bbtextarea', 'desc1', 'Enter the description:');
     $form->addElement('bbtextarea', 'desc2', 'Enter the description (no toolbar):');
     $form->addElement('bbtextarea', 'desc3', 'Enter the description:');
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Update the no toolbar element
     $element =& $form->getElement('desc2');
     $element->clearButtons();
     // Add a popup window to the third description
     $element =& $form->getElement('desc3');
     $element->addPopupWindow('form.php?do=selector&field=firstForm_desc3&tag=img', 'select image');
     $element->addPopupWindow('form.php?do=selector&field=firstForm_desc3&tag=url', 'select url');
     // Apply a filter
     $form->addFilter('name', 'trim');
     $form->addFilter('desc1', 'safe_html');
     // Add a rule
     $form->addRule('name', 'required', 'Please enter your name');
     // Process the form
     if ($form->validate()) {
         // Show the form values
         YDDebugUtil::dump($form->getValues());
         // Mark the form as valid
         $this->template->assign('formValid', true);
     }
     // Add the form to the template
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:40,代码来源:form.php

示例12: actionDefault

 function actionDefault()
 {
     // Mark the form as not valid
     $this->setVar('formValid', false);
     // Create the form
     $form = new YDForm('emailForm');
     // Add the elements
     $form->addElement('text', 'email', 'Enter your email address:', array('style' => 'width: 300px;'));
     $form->addElement('submit', 'cmdSubmit', 'Send');
     // Apply a filter
     $form->addFilter('email', 'trim');
     // Add a rule
     $form->addRule('email', 'email', 'Please enter a valid email address');
     // Process the form
     if ($form->validate()) {
         // Mark the form as valid
         $this->setVar('formValid', true);
         // Parse the template for the email
         $emlTpl = new YDTemplate();
         $emlTpl->setVar('email', $form->getValue('email'));
         $body = $emlTpl->getOutput('email_template');
         // Send the email
         $eml = new YDEmail();
         $eml->setFrom('pieter@yellowduck.be', YD_FW_NAME);
         $eml->addTo($form->getValue('email'), 'Yellow Duck');
         $eml->setSubject('Hello from Pieter & Fiona!');
         $eml->setHtmlBody($body);
         $eml->addAttachment('email.tpl');
         $eml->addHtmlImage('fsimage.jpg', 'image/jpeg');
         $result = $eml->send();
         // Add the result
         $this->setVar('result', $result);
     }
     // Add the form to the template
     $this->setVar('form_html', $form->toHtml());
     $this->addForm('form', $form);
     // Output the template
     $this->outputTemplate();
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:39,代码来源:email.php

示例13: actionDefault

 function actionDefault()
 {
     // Check for the config file
     if (is_file(dirname(__FILE__) . '/include/config.php')) {
         $this->redirectToAction('error');
     }
     // Get the list of skins
     $dir = new YDFSDirectory(dirname(__FILE__) . '/' . $this->dir_skins);
     $items = $dir->getContents('!.*', '', array('YDFSDirectory'));
     $skins = array();
     foreach ($items as $item) {
         $skins[$item] = $item;
     }
     // Get the list of languages
     $dir = new YDFSDirectory(dirname(__FILE__) . '/include/languages/');
     $items = $dir->getContents('language_*.php', '', array('YDFSFile'));
     $languages = array();
     foreach ($items as $item) {
         $item = substr($item, 9, -4);
         $languages[$item] = $item;
     }
     // Create the configuration form
     $form = new YDForm('configForm');
     // Add the fields
     $form->addElement('text', 'db_host', 'Database host', array('class' => 'tfM'));
     $form->addElement('text', 'db_name', 'Database name', array('class' => 'tfM'));
     $form->addElement('text', 'db_user', 'Database user', array('class' => 'tfM'));
     $form->addElement('password', 'db_pass', 'Database password', array('class' => 'tfM'));
     $form->addElement('text', 'db_prefix', 'Database table prefix', array('class' => 'tfM'));
     $form->addElement('text', 'weblog_title', 'Weblog title', array('class' => 'tfM'));
     $form->addElement('text', 'weblog_description', 'Weblog description', array('class' => 'tfM'));
     $form->addElement('select', 'weblog_skin', 'Weblog skin', array('class' => 'tfM', 'style' => 'width: 100%'), $skins);
     $form->addElement('select', 'weblog_language', 'Weblog language', array('class' => 'tfM', 'style' => 'width: 100%'), $languages);
     $form->addElement('text', 'name', 'User name', array('class' => 'tfM'));
     $form->addElement('text', 'email', 'User email', array('class' => 'tfM'));
     $form->addElement('password', 'password', 'Password', array('class' => 'tfM'));
     $form->addElement('submit', '_cmdSubmit', 'Install', array('class' => 'button'));
     // Add the rules
     $form->addRule('db_host', 'required', 'Database host is required');
     $form->addRule('db_name', 'required', 'Database name is required');
     $form->addRule('db_user', 'required', 'Database user is required');
     $form->addRule('weblog_title', 'required', 'Weblog title is required');
     $form->addRule('name', 'required', 'User name is required');
     $form->addRule('email', 'email', 'User email is required');
     $form->addRule('password', 'required', 'Password is required');
     $form->addFormRule(array(&$this, 'checkInstallParams'));
     // Set the defaults
     $form->setDefault('db_host', 'localhost');
     $form->setDefault('db_name', 'ydweblog');
     $form->setDefault('db_user', 'root');
     $form->setDefault('db_prefix', 'ydw_');
     $form->setDefault('weblog_title', 'My Weblog');
     $form->setDefault('weblog_description', 'Description of my Weblog');
     // Process the form
     if ($form->validate() === true) {
         // Get the form values
         $values = $form->getValues();
         // Connect to the database
         $db = YDDatabase::getInstance('mysql', $values['db_name'], $values['db_user'], $values['db_pass'], $values['db_host']);
         // Create the tables
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'categories;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'categories ( id int(11) NOT NULL auto_increment, title varchar(255) NOT NULL default \'\', created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY  (id) ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'comments;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'comments (
                   id int(11) NOT NULL auto_increment,
                   item_id int(11) NOT NULL default \'1\',
                   username varchar(255) NOT NULL default \'\',
                   useremail varchar(255) NOT NULL default \'\',
                   userwebsite varchar(255) default NULL,
                   userip varchar(20) default NULL,
                   comment longtext NOT NULL,
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY item_id (item_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'items;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'items (
                   id int(11) NOT NULL auto_increment,
                   category_id int(11) default \'1\',
                   user_id int(11) NOT NULL default \'1\',
                   title varchar(255) NOT NULL default \'\',
                   body longtext NOT NULL,
                   body_more longtext NOT NULL,
                   num_comments int(11) NOT NULL default \'0\',
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
                   KEY category_id (category_id),
                   KEY user_id (user_id)
                 ) TYPE=MyISAM;');
         $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'links;');
         $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'links (
                   id int(11) NOT NULL auto_increment,
                   title varchar(255) NOT NULL default \'\',
                   url varchar(255) NOT NULL default \'\',
                   num_visits int(11) default \'0\',
                   created int(11) default NULL,
                   modified int(11) default NULL,
                   PRIMARY KEY  (id),
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:101,代码来源:install.php

示例14: actionManageForums

 function actionManageForums()
 {
     // Create the addForum form
     $form = new YDForm('forumForm');
     $form->addElement('text', 'forumTitle', t('admin.newforumtitle'), array("size" => 40));
     $form->addElement('text', 'forumPoids', t('admin.forumweightorder'), array());
     $form->addElement('submit', 'cmdSubmit', t('admin.forumcreate'));
     // Add rules
     $form->addFormRule(array(&$this, 'checkNewForum'));
     $form->addRule('forumPoids', 'numeric', t('admin.forumweightinteger'));
     // Process the form
     if ($form->validate()) {
         // get and show results
         $forum = new ForumObject($form->getValue('forumTitle'), $form->getValue('forumPoids'));
         $forum->insert();
     }
     // Future defaults values
     $form->setDefaults(array('forumTitle' => ''));
     $form->setDefaults(array('forumPoids' => ''));
     // retrieve existing forums
     $forumLogic = new ForumsLogic();
     $forums = $forumLogic->retrieveAllByOrderSimple();
     // Assign variables to the template
     $this->actionTpl->assign('form', $form->toArray());
     $this->actionTpl->assign('forums', $forums);
     $content = new Page($this->actionTpl->fetch('templates/admin.forums.list.tpl'), t('admin.manageforums'), $this->menusAdmin);
     // Display the action template into the master template
     $this->display($content);
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:29,代码来源:admin.php

示例15: getFormPage

 /**
  *  This function returns the page form (form admin edition)
  *
  *  @returns    YDForm object
  */
 function getFormPage()
 {
     YDInclude('YDForm.php');
     // get template and language object
     $templates = YDCMComponent::module('YDCMTemplates');
     $languages = YDCMComponent::module('YDCMLanguages');
     // create access options
     $access = array(0 => t('public'), 1 => t('private'));
     // create 'template pack' options
     $template_pack = array(1 => t('use templatepack') . ' (' . $templates->template_pack() . ')', 0 => t('use custom template'));
     // create form object
     $form = new YDForm(YDConfig::get('YDCMPAGE_FORMPAGE'));
     $form->addElement('text', 'reference', t('page_reference'), array('size' => 25, 'maxlength' => 35));
     $form->addElement('text', 'title', t('page_title'), array('size' => 70, 'maxlength' => 70));
     $form->addElement('textarea', 'html', t('page_html'));
     $form->addElement('textarea', 'xhtml', t('page_xhtml'));
     $form->addElement('select', 'access', t('page_access'), array(), $access);
     $form->addElement('select', 'state', t('page_state'), array(), array(1 => t('yes'), 0 => t('no'), 2 => t('schedule')));
     $form->addElement('datetimeselect', 'published_date_start', t('page_startdate'));
     $form->addElement('datetimeselect', 'published_date_end', t('page_enddate'));
     $form->addElement('select', 'template_pack', '', array(), $template_pack);
     $form->addElement('select', 'template', t('page_template'), array(), $templates->visitors_templates());
     $form->addElement('select', 'metatags', t('page_metatags'), array(), array(0 => t('no'), 1 => t('yes')));
     $form->addElement('textarea', 'description', t('page_description'), array('cols' => 50, 'rows' => 5));
     $form->addElement('textarea', 'keywords', t('page_keywords'), array('cols' => 50, 'rows' => 5));
     $form->addElement('select', 'searcheable', t('page_search'), array(), array(0 => t('no'), 1 => t('yes')));
     $form->addElement('hidden', 'content_id');
     $form->addElement('hidden', 'parent_id');
     $form->addElement('hidden', 'language_id');
     // parent of new page is 0 by default
     $form->setDefault('content_id', 0);
     $form->setDefault('parent_id', 0);
     $form->setDefault('language_id', $languages->adminDefault());
     // add form rules
     $form->addRule('reference', 'required', t('reference_required'));
     $form->addRule('reference', 'alphanumeric', t('reference_alphanumeric'));
     $form->addRule('reference', 'maxwords', t('reference_maxwords'), 1);
     $form->addRule('reference', 'maxlength', t('reference_maxlength'), 100);
     $form->addRule('title', 'required', t('title_required'));
     $form->addRule('title', 'maxlength', t('title_maxlength'), 255);
     $form->addRule('content_id', 'required', t('content_id_required'));
     $form->addRule('content_id', 'numeric', t('content_id_numeric'));
     $form->addRule('parent_id', 'required', t('parent_id_required'));
     $form->addRule('parent_id', 'numeric', t('parent_id_numeric'));
     $form->addRule('html', 'maxlength', t('html_maxlength'), 50000);
     $form->addRule('xhtml', 'maxlength', t('xhtml_maxlength'), 50000);
     $form->addRule('template_pack', 'in_array', t('template_pack_invalid'), array(0, 1));
     $form->addRule('template', 'in_array', t('template_invalid'), array_keys($templates->visitors_templates()));
     $form->addRule('metatags', 'in_array', t('metatags_invalid'), array(0, 1));
     $form->addRule('description', 'maxlength', t('description_maxlength'), 2000);
     $form->addRule('keywords', 'maxlength', t('keywords_maxlength'), 2000);
     return $form;
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:58,代码来源:YDCMPage.php


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