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'); }
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(); }
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'); }
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(); }
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(); }
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(); }
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(); }
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); }
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(); }
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:'******'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'); }
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(); } }
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(); }
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(); }
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'); }
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(); }
function actionDefault() { // Create the form $form = new YDForm('myForm'); $form->setDefaults(array('name' => 'Joe User')); $form->addElement('text', 'loginName', 'User name:'); $form->addElement('password', 'loginPass', 'Password:'******'submit', 'cmdSubmit', 'Login'); // Add the form rule $form->addFormRule(array(&$this, 'checkLogin')); // Process the form if ($form->validate()) { YDDebugUtil::dump($form->getValues()); } else { $form->display(); } }
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'); }
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'); }
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(); } }
function actionDefault() { // create a form with a span and two buttons $form = new YDForm('myform'); $form->addElement('span', 'myspanresult', ' ', array('style' => 'WIDTH:350px;BACKGROUND-COLOR:#ccccff')); $form->addElement('button', 'mybutton', 'Get YDFramework version'); $form->addElement('button', 'mybutton2', 'Get time'); // create ajax object $this->ajax = new YDAjax($this->tpl, $form); // register element mybutton with event result and fixed argument '1' and mybutton2 with event 'result' with argument 2 $this->ajax->addEvent('mybutton', array(&$this, 'result'), 1); $this->ajax->addEvent('mybutton2', array(&$this, 'result'), 2); // process events added $this->ajax->processEvents(); // assign form and display template $this->tpl->assign('title', 'This is a two buttons example with a different event assigned for each one'); $this->tpl->assign('form', $form->tohtml()); $this->tpl->display('general'); }
function actionDefault() { // create a form with a 2 texts, a button and a span for result $form = new YDForm('myform'); $form->addElement('text', 'arg1', 'X:'); $form->addElement('text', 'arg2', 'Y:'); $form->addElement('button', 'mybutton', 'Sum'); $form->addElement('span', 'myspanresult', ' '); // create ajax object $this->ajax = new YDAjax($this->tpl, $form); // assign 'mybutton' with 'compute' call with dynamic values from form elements 'arg1' and 'arg2' $this->ajax->addEvent('mybutton', array(&$this, 'compute'), array('arg1', 'arg2')); // process events added $this->ajax->processEvents(); // assign form and display template $this->tpl->assign('title', 'This a calculator example. Fill X and Y'); $this->tpl->assign('form', $form->tohtml()); $this->tpl->display('general'); }
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(); }
function actionDefault() { // create a form with a 2 texts, a select to choose operation, a button and a span for result $form = new YDForm('myform'); $form->addElement('text', 'arg1', 'X:'); $form->addElement('select', 'operation', 'Operation', array(), array(0 => '+', '-', 'x', '/')); $form->addElement('text', 'arg2', 'Y:'); $form->addElement('span', 'myspanresult', ' '); $form->addElement('button', 'mybutton', 'Calc'); // create ajax object $this->ajax = new YDAjax($this->tpl, $form); // assign 'mybutton' with 'compute' call with dynamic values from form elements 'arg1', 'arg2' and 'operation' $this->ajax->addEvent('mybutton', array(&$this, 'compute'), array('arg1', 'arg2', 'operation')); // process events added $this->ajax->processEvents(); // assign form and display template $this->tpl->assign('title', 'This a dynamic calculator example (you can choose operation)'); $this->tpl->assign('form', $form->tohtml()); $this->tpl->display('general'); }
function actionDefault() { // Get the list of files and file sizes $cache_pub_lbl = 'Public cache ' . $this->_getTotalSizeAndCountAsText(YD_WEBLOG_CACHE_PREFIX . '*.' . YD_WEBLOG_CACHE_SUFFIX); $cache_tmb_lbl = 'Thumbnail cache ' . $this->_getTotalSizeAndCountAsText(YD_TMP_PRE . 'N_*.*'); $cache_web_lbl = 'Web download cache ' . $this->_getTotalSizeAndCountAsText('*.wch'); $cache_tpl_lbl = 'Template cache ' . $this->_getTotalSizeAndCountAsText('*.tpl.php'); // Create the delete form $form = new YDForm('clearCacheForm'); $form->addElement('checkbox', 'cache_pub', $cache_pub_lbl, array('style' => 'border: none;')); $form->addElement('checkbox', 'cache_tmb', $cache_tmb_lbl, array('style' => 'border: none;')); $form->addElement('checkbox', 'cache_web', $cache_web_lbl, array('style' => 'border: none;')); $form->addElement('checkbox', 'cache_tpl', $cache_tpl_lbl, array('style' => 'border: none;')); $form->addElement('submit', '_cmdSubmit', t('cleanup'), array('class' => 'button')); $form->setDefaults(array('cache_pub' => 1, '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_pub')) { $this->_deleteCacheFiles(YD_WEBLOG_CACHE_PREFIX . '*.' . YD_WEBLOG_CACHE_SUFFIX); } // Check if we need to delete the thumbnail objects if ($form->getValue('cache_tmb') == 1) { $this->_deleteCacheFiles(YD_TMP_PRE . 'N_*.*'); } // Check if we need to delete the web objects if ($form->getValue('cache_web')) { $this->_deleteCacheFiles('*.wch'); } // Check if we need to delete the template objects if ($form->getValue('cache_tpl')) { $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(); }
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(); }
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(); }
function actionDefault() { // create 2 forms with a 1 autocompleters each and a simple text element $form1 = new YDForm('myform1'); $form1->addElement('autocompleter', 'arg1', 'Country with standard style:', '', array(&$this, 'getCountry')); $form1->addElement('text', 'arg2', 'Just a simple text box without autocompleter'); $form2 = new YDForm('myform2'); $form2->addElement('autocompleter', 'arg3', 'Country with custom style:', array('style' => 'width:300px; background-color:#CCFFFF;'), array(&$this, 'getCountry')); $form2->addElement('text', 'arg4', 'Just another text box'); // create ajax object $this->ajax = new YDAjax($this->tpl); $this->ajax->addForm($form1); $this->ajax->addForm($form2); // add focus effect to 'arg2' form element. Simple, hein? ;) $this->ajax->addEffect(new YDAjaxEffect('arg2', 'focus')); // process events added $this->ajax->processEvents(); // assign form and display template $this->tpl->assign('title', 'This example demonstrates 2 autocompleters and a text element with focus'); $this->tpl->assign('form', $form1->tohtml() . $form2->tohtml()); $this->tpl->display(); }
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('*****@*****.**', 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(); }
function actionDefault() { // create a form with a span and a button $form = new YDForm('myform'); $form->addElement('span', 'myspanresult', ' ', array('style' => 'WIDTH:350px;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')); // add confirmation to mybutton call $this->ajax->addConfirmation('mybutton', 'Are you shure you want to get ydf version?'); // create an alias (submitCall). you can see a new function submitCall() is js client code // note that, addAlias is defined AFTER addConfirmation, then submitCall() will have confirmation too // alias BEFORE addConfirmation will assign submitCall() with a clean event $this->ajax->addAlias('mybutton', 'submitCall()'); // process ajax events $this->ajax->processEvents(); // assign form and display template $this->tpl->assign('title', 'This demonstrates how to add confirmations and aliases'); $this->tpl->assign('form', $form->tohtml()); $this->tpl->display('general'); }
function actionDefault() { // Create the form $form = new YDForm('form1'); // Add a first set of elements $elementDate = $form->addElement('dateselect', 'dateSelect1', 'Enter data:'); $elementTime = $form->addElement('timeselect', 'timeSelect1', 'Enter data:'); $elementDateTime = $form->addElement('datetimeselect', 'datetimeSelect1', 'Enter data:'); // Add a second set of elements $form->addElement('dateselect', 'dateSelect2', 'Enter data:', array(), array('yearstart' => 1970, 'yearend' => '2050')); $form->addElement('timeselect', 'timeSelect2', 'Enter data:'); $form->addElement('datetimeselect', 'datetimeSelect2', 'Enter data:', array(), array('yearstart' => 1970, 'yearend' => '2050')); $form->addElement('datetimeselect', 'datetimeSelect3', 'Enter data with seconds:', array(), array('seconds' => true)); // Add the send button $form->addElement('submit', 'cmd1', 'Send'); // Set the defaults $form->setDefaults(array('dateSelect1' => array('month' => 4, 'day' => 4, 'year' => 2002), 'dateSelect2' => strval(time()), 'timeSelect2' => strval(time()), 'datetimeSelect2' => time() + 3600 * 24)); // Display the form $form->display(); // Show the contents of the form if (YDConfig::get('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('dateSelect1'), 'dateSelect1'); YDDebugUtil::dump($form->getValue('timeSelect1'), 'timeSelect1'); YDDebugUtil::dump($form->getValue('datetimeSelect1'), 'datetimeSelect1'); YDDebugUtil::dump($form->getValues(), '$form->getValues()'); YDDebugUtil::dump($_POST, '$_POST'); YDDebugUtil::dump($_FILES, '$_FILES'); } if ($form->validate()) { YDDebugUtil::dump($form->getValues(), '$form->getValues()'); 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" )'); YDDebugUtil::dump(YDStringUtil::formatDate($elementDateTime, 'datetime', 'pt'), 'YDStringUtil::formatDate'); } }