本文整理汇总了PHP中YDForm::addElement方法的典型用法代码示例。如果您正苦于以下问题:PHP YDForm::addElement方法的具体用法?PHP YDForm::addElement怎么用?PHP YDForm::addElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YDForm
的用法示例。
在下文中一共展示了YDForm::addElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionDefault
function actionDefault()
{
// create a form with a span and a button
$form = new YDForm('myform');
$form->addElement('span', 'myspanresult', ' ', array('style' => 'BACKGROUND-COLOR:#ccccff'));
$form->addElement('button', 'mybutton', 'Get version');
// create ajax object
$this->ajax = new YDAjax($this->tpl);
$this->ajax->addForm($form);
// create custom effects for waiting message
$onStart = new YDAjaxEffect('', 'opacity', 'hide()', 0);
$onShow = new YDAjaxEffect('', 'opacity', 'custom(0,1)', 0);
$onHide = new YDAjaxEffect('', 'opacity', "toggle()");
// use waiting message with custom effects
$this->ajax->useWaitingMessage('<h2>Please wait . . .</h2>', array(), $onStart, $onShow, $onHide);
// to use default waiting message just try:
// $this->ajax->useWaitingMessage();
// register element mybutton (mybutton will be assigned with 'getversion' call in the client side)
$this->ajax->addEvent('mybutton', array(&$this, 'getversion'));
// process ajax events
$this->ajax->processEvents();
// assign form and display template
$this->tpl->assign('title', 'This example demonstrates the waiting message with custom parameters on a slow server');
$this->tpl->assign('form', $form->tohtml());
$this->tpl->display('general');
}
示例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();
}
示例3: 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');
}
示例4: actionDefault
function actionDefault()
{
// Create the delete form
$form = new YDForm('clearCacheForm');
$form->addElement('checkbox', 'cache_tmb', 'Thumbnail cache');
$form->addElement('checkbox', 'cache_web', 'Web download cache');
$form->addElement('checkbox', 'cache_tpl', 'Template cache');
$form->addElement('submit', '_cmdSubmit', t('cleanup'), array('class' => 'button'));
$form->setDefaults(array('cache_web' => 1, 'cache_tmb' => 1, 'cache_tpl' => 1));
// Validate the form
if ($form->validate() == true) {
// Check if we need to delete the thumbnail objects
if ($form->getValue('cache_tmb') === 'on') {
$this->_deleteCacheFiles('*.tmn');
}
// Check if we need to delete the web objects
if ($form->getValue('cache_web') === 'on') {
$this->_deleteCacheFiles('*.wch');
}
// Check if we need to delete the template objects
if ($form->getValue('cache_tpl') === 'on') {
$this->_deleteCacheFiles('*.tpl.php');
}
// Add a status message
$this->tpl->assign('message', t('cache_cleaned_up'));
}
// Add the form to the template
$this->tpl->assignForm('form', $form);
// Display the template
$this->display();
}
示例5: 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();
}
示例6: 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();
}
示例7: actionDefault
function actionDefault()
{
// Create the form
$form = new YDForm('form1');
$elementDate = $form->addElement('dateselect', 'dateSelect1', 'Enter data:');
$elementDate = $form->addElement('dateselect', 'dateSelect2', 'Enter data:');
$elementTime = $form->addElement('timeselect', 'timeSelect1', 'Enter data:');
$elementDateTime = $form->addElement('datetimeselect', 'datetimeSelect1', 'Enter data:');
$form->addElement('submit', 'cmd1', 'Send');
$form->setDefaults(array('dateSelect1' => array('month' => 4, 'day' => 4, 'year' => 2002)));
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($elementDate->getTimeStamp(), '$elementDate->getTimeStamp()');
YDDebugUtil::dump($elementDate->getTimeStamp('%d/%m/%Y'), '$elementDate->getTimeStamp( "%d/%m/%Y" )');
YDDebugUtil::dump(date('M-d-Y', $elementDate->getTimeStamp()), '$elementDate->gdate( getTimeStamp() )');
YDDebugUtil::dump($elementTime->getTimeStamp(), '$elementTime->getTimeStamp()');
YDDebugUtil::dump($elementTime->getTimeStamp('%H:%M'), '$elementTime->getTimeStamp( "%H:%M" )');
YDDebugUtil::dump($elementDateTime->getTimeStamp(), '$elementDateTime->getTimeStamp()');
YDDebugUtil::dump($elementDateTime->getTimeStamp('%d/%m/%Y %H:%M'), '$elementDateTime->getTimeStamp( "%H:%M" )');
}
$form->display();
}
示例8: actionSearch
function actionSearch()
{
// retrieve list of forums
$forumLogic = new ForumsLogic();
$forums = $forumLogic->retrieveAllByOrderSimple();
$selectForums = array();
foreach ($forums as $i => $item) {
$selectForums["" . $item->id] = $item->name;
}
// Create the search form
$form = new YDForm('searchForm');
$form->addElement('text', 'searchKeys', t('forums.searchstring'), array("size" => 40));
$form->addElement('select', 'searchForum', t('forums.searchforum'), array("width" => 60), $selectForums);
$form->addElement('submit', 'cmdSubmit', t('forums.search'));
// Add rules
$form->addFormRule(array(&$this, 'checkSearch'));
// Process the form
if ($form->validate()) {
$this->actionTpl->assign('searched', true);
// get and show results
$forum = $forumLogic->retrieveForumById($form->getValue('searchForum'));
$forum->loadSubjectsMatching($form->getValue('searchKeys'));
// number of results
$this->actionTpl->assign('nbposts', count($forum->subjects));
$this->actionTpl->assign('posts', $forum->subjects);
}
// Assign variables to the template
$this->actionTpl->assign('form', $form->toArray());
$content = new page($this->actionTpl->fetch('templates/forums.search.tpl'), t('forums.searching'));
$this->display($content);
}
示例9: 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();
}
示例10: actionLogin
function actionLogin()
{
// Redirect to default action if already logged in
if ($this->isAuthenticated() === true) {
$this->forward('default');
return;
}
// Create the login form
$form = new YDForm('loginForm');
$form->setDefaults(array('name' => 'Joe User'));
$form->addElement('text', 'loginName', 'User name:');
$form->addElement('password', 'loginPass', 'Password:');
$form->addElement('submit', 'cmdSubmit', 'Login');
// Add the rules
$form->addFormRule(array(&$this, 'checkLogin'));
// Process the form
if ($form->validate()) {
// Get username and password
$usrName = $form->getValue('loginName');
$usrPass = $form->getValue('loginPass');
// Mark the session that we are logged in
$_SESSION['usrName'] = 'pieter';
$_SESSION['isLoggedIn'] = true;
// Mark the form as valid
$this->authenticationSucceeded();
$this->forward('default');
return;
}
// Add the form to the template
$this->template->assignForm('form', $form);
// Output the template
$this->template->display('login');
}
示例11: 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();
}
}
示例12: 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();
}
示例13: actionForm
function actionForm()
{
// Create the form
$form = new YDForm('form1', 'GET');
// Add elements
$form->addElement('text', 'txt', 'Enter text:');
$form->addElement('submit', 'cmdSubmit', 'submit');
// Display the form
$this->template->assign('form', $form->toHtml());
// Display the template
$this->template->display();
}
示例14: actionDefault
function actionDefault()
{
// create a form with two select buttons
$form = new YDForm('myform');
$form->addElement('select', 'car', '', array(), array('Please select your car', 'Ferrari', 'Fiat', 'BMW'));
$form->addElement('select', 'model', '', array());
// create ajax object
$this->ajax = new YDAjax($this->tpl, $form);
// register event to element 'car' and send to 'getmodel' method its dynamic value
$this->ajax->addEvent('car', array(&$this, 'getmodel'), array('car'));
$this->ajax->processEvents();
// assign form and display template
$this->tpl->assign('title', 'Dependency with two select elements:');
$this->tpl->assign('form', $form->render('html'));
$this->tpl->display('general');
}
示例15: actionDefault
function actionDefault()
{
// create a form with a 2 autocompleters and a simple text element
$form = new YDForm('myform');
$form->addElement('autocompleter', 'arg1', 'Country with standard style:', '', array(&$this, 'getCountry'));
$form->addElement('text', 'arg2', 'Just a simple text box without autocompleter');
$form->addElement('autocompleter', 'arg3', 'Country with custom style:', array('style' => 'width:300px; background-color:#CCFFFF;'), array(&$this, 'getCountry'));
// create ajax object
$this->ajax = new YDAjax($this->tpl, $form);
// process events added
$this->ajax->processEvents();
// assign form and display template
$this->tpl->assign('title', 'Just start typing a coutry name in the box to see the effect');
$this->tpl->assign('form', $form->tohtml());
$this->tpl->display();
}