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()
 {
     // 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();
 }
 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 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 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 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 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()
 {
     // 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();
 }
 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 span and a button
     $form = new YDForm('myform');
     $form->addElement('span', 'myspanresult', '&nbsp;', 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();
 }
 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();
 }
 /**
  *	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>';
 }
 /**
  *        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>';
 }
 function actionDefault()
 {
     // create a form with a span and a button
     $form = new YDForm('myform');
     $form->addElement('span', 'myspanresult', '&nbsp;', 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');
 }
 /**
  *	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' => $this->_type, 'name' => $this->_form . '_' . $this->_name, 'src' => $this->_value);
     $attribs = array_merge($this->_attributes, $attribs);
     // Get the HTML
     return '<input' . YDForm::_convertToHtmlAttrib($attribs) . ' />';
 }
 /**
  *	This function will return the element as HTML.
  *
  *	@returns	The form element as HTML text.
  */
 function toHtml()
 {
     // Create the list of attributes
     $attribs = array('name' => $this->_form . '_' . $this->_name);
     $attribs = array_merge($this->_attributes, $attribs);
     // Get the HTML
     return '<textarea' . YDForm::_convertToHtmlAttrib($attribs) . '>' . $this->_value . '</textarea>';
 }
 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()
 {
     // create a form with a span and two buttons
     $form = new YDForm('myform');
     $form->addElement('span', 'myspanresult', '&nbsp;', 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 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 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();
     }
 }
 /**
  *	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' => $this->_type, 'name' => $this->_form . '_' . $this->_name, 'id' => $this->_form . '_' . $this->_name);
     $attribs = array_merge($this->_attributes, $attribs);
     // If a value, fill it in and make it checked
     if (!empty($this->_value)) {
         $attribs['checked'] = '';
     }
     // Get the HTML
     return '<input' . YDForm::_convertToHtmlAttrib($attribs) . '>';
 }
 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();
 }
 /**
  *	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' => $this->_type, 'name' => $this->_form . '_' . $this->_name, 'value' => $this->_value);
     $attribs = array_merge($this->_attributes, $attribs);
     // check dynamic
     if ($this->_dynamic) {
         $attribs['onfocus'] = "if(this.value=='" . $this->_value . "'){this.value=''};";
         $attribs['onblur'] = "if(this.value==''){this.value='" . $this->_value . "'};";
     }
     // Get the HTML
     return '<input' . YDForm::_convertToHtmlAttrib($attribs) . ' />';
 }
 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 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();
 }
 /**
  *	This function will return the element as HTML.
  *
  *	@returns	The form element as HTML text.
  */
 function toHtml()
 {
     // Create the list of attributes
     $attribs = array('name' => $this->_form . '_' . $this->_name);
     $attribs = array_merge($this->_attributes, $attribs);
     // check if we are in a Javascript environment
     if (YDConfig::get('YD_FORMELEMENT_TEXTAREA_NL')) {
         $this->_value = preg_replace("/\r*\n/", "\\n", $this->_value);
         $this->_value = preg_replace("/\\//", "\\\\/", $this->_value);
         $this->_value = preg_replace("/'/", " ", $this->_value);
     }
     // Get the HTML
     return '<textarea' . YDForm::_convertToHtmlAttrib($attribs) . '>' . $this->_value . '</textarea>';
 }
 function actionDefault()
 {
     // create a form with a span and a button
     $form = new YDForm('myform');
     $form->addElement('span', 'myspanresult', '&nbsp;', 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');
     $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 actionDefault()
 {
     // create a form with a datetimeselect, 3 selects, a button and a span for result
     $form = new YDForm('myform');
     $form->addElement('datetimeselect', 'currentdate', 'Current date');
     $form->addElement('select', 'operation', '', array(), array('+', '-'));
     $form->addElement('select', 'number', '', array(), array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
     $form->addElement('select', 'type', '', array(), array('minutes', 'days', 'months', 'years'));
     $form->addElement('span', 'myspanresult', '?');
     $form->addElement('button', 'mybutton', '=');
     // create ajax object
     $this->ajax = new YDAjax($this->tpl, $form);
     // register button 'mybutton' with event 'result' and arguments form elements
     $this->ajax->addEvent('mybutton', array(&$this, 'result'), array('currentdate', 'operation', 'number', 'type'));
     $this->ajax->processEvents();
     // assign form and display template
     $this->tpl->assignForm('form', $form);
     $this->tpl->display();
 }