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 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 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() { // 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() { // Create the form $form = new YDForm('form1'); // Add elements $form->addElement('text', 'username', 'Fill a username that starts with spaces'); $form->addElement('text', 'name', 'Fill a small caps name'); $form->addElement('datetimeselect', 'date1', 'Date1'); $form->addElement('date', 'date2', 'Date2'); $form->addElement('datetimeselect', 'date3', 'Date3'); $form->addElement('datetimeselect', 'date4', 'Date4'); $form->addElement('submit', '_cmdSubmit', 'Submit'); // Some defaults $form->setDefault('username', ' myuser'); $form->setDefault('name', 'igor'); // Add filters $form->addFilter('username', 'trim'); // must return eg 'myuser' $form->addFilter('name', 'upper'); // must return eg 'IGOR' if ($form->validate()) { // IMPORTANT NOTE: 'dateformat' filters must be always added AFTER form validation ! // On form validation checking (by $form->validate()), 'dateformat' filter is applyed and // element is not populated again because date result array is lost. // This is why form is not displayed correctly after validation // (if some rule is broken you would not get the date element with correct values) $form->addFilter('date2', 'dateformat', 'day'); // must return eg '20' $form->addFilter('date3', 'dateformat', 'datetimesql'); // must return eg '2005-02-01 10:00:00' $form->addFilter('date4', 'dateformat', "%b"); // must return eg 'Aug' YDDebugUtil::dump($form->getValues(), '$form->getValues()'); } else { // Display form $form->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(); }