本文整理汇总了PHP中YDForm类的典型用法代码示例。如果您正苦于以下问题:PHP YDForm类的具体用法?PHP YDForm怎么用?PHP YDForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了YDForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: 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 3 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();
}
示例3: 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');
}
示例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');
}
示例5: 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);
}
示例6: actionDefault
function actionDefault()
{
// create options and attributes
$options = array('pt' => 'Portugal', 'br' => 'Brasil', 'be' => 'Belgium');
$attributes = array('src' => YDUrl::makeLinkAbsolute('./flags/'), 'ext' => 'gif');
// Create the form and add element
$form = new YDForm('form1');
$form->addElement('selectimage', 'si', 'Select country', $attributes, $options);
// Display the template
$form->display();
}
示例7: 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();
}
示例8: actionDefault
function actionDefault()
{
// crete a simple form
$form = new YDForm('myform');
$form->addElement('button', 'mybutton', 'Standard form button event');
// add an event to form button, JS event and default event handling
$this->ajax->addForm($form);
$this->ajax->addEvent('mybutton', array(&$this, 'buttonEvent'));
$this->ajax->addEvent('customEvent(x)', array(&$this, 'customEvent'), 'var x');
$this->ajax->addEvent('*', array(&$this, 'defaultOne'));
// process all events
$this->ajax->processEvents();
$this->template->assign('form', $form->toHTML());
$this->template->display();
}
示例9: 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');
}
示例10: 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'));
// create ajax object
$this->ajax = new YDAjax($this->tpl, $form);
// register custom function
$this->ajax->addEvent('customFunction()', array(&$this, 'getversion'));
// process ajax events
$this->ajax->processEvents();
// assign form and display template
$this->tpl->assign('title', 'This is a simple ajax example');
$this->tpl->assign('form', $form->tohtml());
$this->tpl->display();
}
示例11: 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();
}
示例12: toHtml
/**
* This function will return the element as HTML.
*
* @returns The form element as HTML text.
*/
function toHtml()
{
// Create the list of attributes
$attribs = array('type' => 'text', 'name' => $this->_form . '_' . $this->_name, 'value' => $this->_value);
$attribs = array_merge($this->_attributes, $attribs);
// trick to make this text box with the same width as autocompleter.
// create a style array and a default width for text and div
$style = array();
$style['width'] = '143px';
// if user has defined a custom style we must parse it to check if width was defined
if (isset($attribs['style'])) {
foreach (explode(";", $attribs['style']) as $att) {
if (trim($att) != '') {
list($name, $value) = split(":", $att);
$style[strtolower($name)] = trim($value);
}
}
}
// compute style attribute
$attribs['style'] = '';
foreach ($style as $name => $value) {
$attribs['style'] .= $name . ':' . $value . ';';
}
// if is a autocompleter we must add an extra div. TODO: automagically apply width to text element and div
return '<input' . YDForm::_convertToHtmlAttrib($attribs) . ' /><div style="display:none; z-index:999;' . $attribs['style'] . '" id="' . $attribs['name'] . '_div"><ul></ul></div>';
}
示例13: toHtml
/**
* This function will return the element as HTML.
*
* @returns The form element as HTML text.
*/
function toHtml()
{
// Create the list of attributes
$attribs = array('id' => $this->_form . '_' . $this->_name);
$attribs = array_merge($this->_attributes, $attribs);
// Get the HTML
return '<span' . YDForm::_convertToHtmlAttrib($attribs) . '>' . nl2br($this->_value) . '</span>';
}
示例14: 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 YDFramework version');
// create ajax object
$this->ajax = new YDAjax($this->tpl, $form);
// 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 is a simple ajax example');
$this->tpl->assign('form', $form->tohtml());
$this->tpl->display('general');
}
示例15: actionDefault
function actionDefault()
{
// create form
$form = new YDForm('myform');
$form->addElement('text', 'mytext', 'Write something, eg: "David" (case sensitive)');
$form->addElement('select', 'items', '', array(), array('Francisco' => 'Francisco', 'Pieter' => 'Pieter', 'David' => 'David'));
// create ajax object
$this->ajax = new YDAjax($this->tpl, $form);
// assign event to mytext
$this->ajax->addEvent('mytext', array(&$this, 'setSelect'), 'mytext', 'onkeyup');
// process all events
$this->ajax->processEvents();
// assign title, form and display template
$this->tpl->assign('title', 'Change selected value on-the-fly example');
$this->tpl->assign('form', $form->render('html'));
$this->tpl->display('general');
}