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(); } }
/** * This method creates a form for post management * * @param $quote_id (optional) Post id to insert in content textarea. * * @returns YDForm object */ function &addFormNew($quote_id = null) { // create form and add elements $form = new YDForm('ydcmforumpost'); $form->addElement('textarea', 'content', 'Content'); $form->addElement('button', 'cmdLogin', 'Submit'); // if we are replying to someone, let's get the content if (is_numeric($quote_id)) { // get replying post $posts = new YDCMForum_posts(); $post = $posts->getElement($quote_id); // apply default to content textarea $form->setDefault('content', $post['post_content']); } return $form; }
/** * This action takes care of handling the login form. It can show and validate a login form and redirects to * default action of the request class when the user is authenticated. */ 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->addElement('text', 'loginName', t('username'), array('class' => 'tfL')); $form->addElement('password', 'loginPass', t('password'), array('class' => 'tfL')); $form->addElement('checkbox', 'loginRememberMe', t('remember_me')); $form->addElement('submit', 'cmdSubmit', 'Login', array('class' => 'button')); $form->setDefault('loginRememberMe', true); // Add the rules $form->addFormRule(array(&$this, 'checkLogin')); // Process the form if ($form->validate()) { // Get the form values $values = $form->getValues(); // Update the password $values['loginPass'] = md5($values['loginPass']); // Set the cookies if ($values['loginRememberMe'] === 1) { $this->setCookie($this->cookieNameUser, $values['loginName'], false); $this->setCookie($this->cookieNamePass, $values['loginPass'], false); } else { $this->setCookie($this->cookieNameUser, $values['loginName'], true); $this->setCookie($this->cookieNamePass, $values['loginPass'], true); } // Forward to the main manage page $this->redirectToAction(); } // Add the form to the template $this->tpl->assignForm('form', $form); // Output the template $this->tpl->displayWithMaster('login'); }
/** * This function returns a form for posts */ function getFormPost() { // create a form for new posts $form = new YDForm(YDConfig::get('YDCMHELPDESK_FORMPOST')); // get urgencies, states and types $urgencies = array_keys(YDConfig::get('YDCMHELPDESK_URGENCIES')); $states = YDConfig::get('YDCMHELPDESK_STATES'); $types = YDConfig::get('YDCMHELPDESK_TYPES'); // delete 'allstates' and 'allurgencies' from states and types array_shift($urgencies); array_shift($states); // add new form elements $form->addElement('text', 'subject', t('ticket_subject'), array('size' => 50)); $form->addElement('select', 'urgency_id', t('ticket_urgency_id'), array(), $urgencies); $form->addElement('select', 'state_id', t('ticket_state_id'), array(), $states); $form->addElement('textarea', 'text', t('ticket_text'), array('cols' => 80, 'rows' => 15)); $form->addElement('span', 'creation_user', t('ticket_creation_user')); $form->addElement('datetimeselect', 'creation_date', t('ticket_creation_date')); $form->addElement('text', 'reportedby_user', t('ticket_reportedby_user'), array('size' => 50)); $form->addElement('select', 'reportedby_type', t('ticket_reportedby_type'), array(), $types); $form->addElement('text', 'reportedby_local', t('ticket_reportedby_local')); $form->addElement('datetimeselect', 'reportedby_date', t('ticket_reportedby_date')); $form->addElement('text', 'assignedto_user', t('ticket_assignedto_user'), array('size' => 50)); $form->addElement('select', 'assignedto_type', t('ticket_assignedto_type'), array(), $types); $form->addElement('text', 'assignedto_local', t('ticket_assignedto_local')); $form->addElement('datetimeselect', 'assignedto_date', t('ticket_assignedto_date')); $form->setDefault('urgency_id', 1); $form->setDefault('state_id', 1); return $form; }
function actionDefault() { // Check for the config file if (is_file(dirname(__FILE__) . '/include/config.php')) { $this->redirectToAction('error'); } // Get the list of skins $dir = new YDFSDirectory(dirname(__FILE__) . '/' . $this->dir_skins); $items = $dir->getContents('!.*', '', array('YDFSDirectory')); $skins = array(); foreach ($items as $item) { $skins[$item] = $item; } // Get the list of languages $dir = new YDFSDirectory(dirname(__FILE__) . '/include/languages/'); $items = $dir->getContents('language_*.php', '', array('YDFSFile')); $languages = array(); foreach ($items as $item) { $item = substr($item, 9, -4); $languages[$item] = $item; } // Create the configuration form $form = new YDForm('configForm'); // Add the fields $form->addElement('text', 'db_host', 'Database host', array('class' => 'tfM')); $form->addElement('text', 'db_name', 'Database name', array('class' => 'tfM')); $form->addElement('text', 'db_user', 'Database user', array('class' => 'tfM')); $form->addElement('password', 'db_pass', 'Database password', array('class' => 'tfM')); $form->addElement('text', 'db_prefix', 'Database table prefix', array('class' => 'tfM')); $form->addElement('text', 'weblog_title', 'Weblog title', array('class' => 'tfM')); $form->addElement('text', 'weblog_description', 'Weblog description', array('class' => 'tfM')); $form->addElement('select', 'weblog_skin', 'Weblog skin', array('class' => 'tfM', 'style' => 'width: 100%'), $skins); $form->addElement('select', 'weblog_language', 'Weblog language', array('class' => 'tfM', 'style' => 'width: 100%'), $languages); $form->addElement('text', 'name', 'User name', array('class' => 'tfM')); $form->addElement('text', 'email', 'User email', array('class' => 'tfM')); $form->addElement('password', 'password', 'Password', array('class' => 'tfM')); $form->addElement('submit', '_cmdSubmit', 'Install', array('class' => 'button')); // Add the rules $form->addRule('db_host', 'required', 'Database host is required'); $form->addRule('db_name', 'required', 'Database name is required'); $form->addRule('db_user', 'required', 'Database user is required'); $form->addRule('weblog_title', 'required', 'Weblog title is required'); $form->addRule('name', 'required', 'User name is required'); $form->addRule('email', 'email', 'User email is required'); $form->addRule('password', 'required', 'Password is required'); $form->addFormRule(array(&$this, 'checkInstallParams')); // Set the defaults $form->setDefault('db_host', 'localhost'); $form->setDefault('db_name', 'ydweblog'); $form->setDefault('db_user', 'root'); $form->setDefault('db_prefix', 'ydw_'); $form->setDefault('weblog_title', 'My Weblog'); $form->setDefault('weblog_description', 'Description of my Weblog'); // Process the form if ($form->validate() === true) { // Get the form values $values = $form->getValues(); // Connect to the database $db = YDDatabase::getInstance('mysql', $values['db_name'], $values['db_user'], $values['db_pass'], $values['db_host']); // Create the tables $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'categories;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'categories ( id int(11) NOT NULL auto_increment, title varchar(255) NOT NULL default \'\', created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY (id) ) TYPE=MyISAM;'); $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'comments;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'comments ( id int(11) NOT NULL auto_increment, item_id int(11) NOT NULL default \'1\', username varchar(255) NOT NULL default \'\', useremail varchar(255) NOT NULL default \'\', userwebsite varchar(255) default NULL, userip varchar(20) default NULL, comment longtext NOT NULL, created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY (id), KEY item_id (item_id) ) TYPE=MyISAM;'); $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'items;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'items ( id int(11) NOT NULL auto_increment, category_id int(11) default \'1\', user_id int(11) NOT NULL default \'1\', title varchar(255) NOT NULL default \'\', body longtext NOT NULL, body_more longtext NOT NULL, num_comments int(11) NOT NULL default \'0\', created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY (id), KEY category_id (category_id), KEY user_id (user_id) ) TYPE=MyISAM;'); $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'links;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'links ( id int(11) NOT NULL auto_increment, title varchar(255) NOT NULL default \'\', url varchar(255) NOT NULL default \'\', num_visits int(11) default \'0\', created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY (id), UNIQUE KEY url (url) ) TYPE=MyISAM;'); $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'pages;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'pages ( id int(11) NOT NULL auto_increment, user_id int(11) NOT NULL default \'1\', title varchar(255) NOT NULL default \'\', body longtext, created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY (id), KEY user_id (user_id) ) TYPE=MyISAM;'); $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'statistics;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'statistics ( id int(11) NOT NULL auto_increment, date date NOT NULL default \'0000-00-00\', uri varchar(255) NOT NULL default \'0\', browser varchar(10) NOT NULL default \'\', platform varchar(10) NOT NULL default \'\', hits int(11) NOT NULL default \'0\', PRIMARY KEY (id) ) TYPE=MyISAM;'); $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'statistics_init;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'statistics_init ( created varchar(10) NOT NULL default \'\' ) TYPE=MyISAM;'); $db->executeSql('DROP TABLE IF EXISTS ' . $values['db_prefix'] . 'users;'); $db->executeSql('CREATE TABLE ' . $values['db_prefix'] . 'users ( id int(11) NOT NULL auto_increment, name varchar(255) NOT NULL default \'\', email varchar(255) NOT NULL default \'\', password varchar(50) default NULL, created int(11) default NULL, modified int(11) default NULL, PRIMARY KEY (id), UNIQUE KEY email (email) ) TYPE=MyISAM;'); $db->executeInsert($values['db_prefix'] . 'statistics_init', array('created' => $db->getDate('__NOW__'))); // Include the weblog API YDInclude(dirname(__FILE__) . '/include/YDWeblogAPI.php'); // Save the config file YDWeblogSaveConfig($values); // Include the config file YDInclude(dirname(__FILE__) . '/include/config.php'); // Create the weblog object $weblog = new YDWeblogAPI(); // Add the user $user = array(); $user['name'] = $values['name']; $user['email'] = $values['email']; $user['password'] = $values['password']; $weblog->saveUser($user); // Add a category $category = array(); $category['title'] = 'General'; $weblog->addCategory($category); // Create a first post $item = array(); $item['category_id'] = 1; $item['user_id'] = 1; $item['title'] = 'Your first post'; $item['body'] = 'Welcome to your weblog'; $item['body_more'] = 'Your extended body'; $weblog->addItem($item); // Create a second post $item = array(); $item['category_id'] = 1; $item['user_id'] = 1; $item['title'] = 'Your second post'; $item['body'] = 'Without an extended body'; $item['created'] = time() + 100; $weblog->addItem($item); // Add a comment $comment = array(); $comment['item_id'] = 1; $comment['username'] = '******'; $comment['useremail'] = '*****@*****.**'; $comment['userwebsite'] = YD_FW_HOMEPAGE; $comment['comment'] = 'A first comment'; $weblog->addComment($comment); // Add a sample page $page = array(); $page['user_id'] = 1; $page['title'] = 'Your first page'; $page['body'] = 'The contents of your first page'; $weblog->addPage($page); // Add a link $link = array(); $link['title'] = 'Yellow Duck Framework'; $link['url'] = 'http://ydframework.berlios.de/'; $weblog->addLink($link); // Redirect to the finish action $this->redirectToAction('finish'); } // Add it to the template $this->tpl->assignForm('form', $form); // Display the template $this->tpl->display(); }
/** * This function returns the page form (form admin edition) * * @returns YDForm object */ function getFormPage() { YDInclude('YDForm.php'); // get template and language object $templates = YDCMComponent::module('YDCMTemplates'); $languages = YDCMComponent::module('YDCMLanguages'); // create access options $access = array(0 => t('public'), 1 => t('private')); // create 'template pack' options $template_pack = array(1 => t('use templatepack') . ' (' . $templates->template_pack() . ')', 0 => t('use custom template')); // create form object $form = new YDForm(YDConfig::get('YDCMPAGE_FORMPAGE')); $form->addElement('text', 'reference', t('page_reference'), array('size' => 25, 'maxlength' => 35)); $form->addElement('text', 'title', t('page_title'), array('size' => 70, 'maxlength' => 70)); $form->addElement('textarea', 'html', t('page_html')); $form->addElement('textarea', 'xhtml', t('page_xhtml')); $form->addElement('select', 'access', t('page_access'), array(), $access); $form->addElement('select', 'state', t('page_state'), array(), array(1 => t('yes'), 0 => t('no'), 2 => t('schedule'))); $form->addElement('datetimeselect', 'published_date_start', t('page_startdate')); $form->addElement('datetimeselect', 'published_date_end', t('page_enddate')); $form->addElement('select', 'template_pack', '', array(), $template_pack); $form->addElement('select', 'template', t('page_template'), array(), $templates->visitors_templates()); $form->addElement('select', 'metatags', t('page_metatags'), array(), array(0 => t('no'), 1 => t('yes'))); $form->addElement('textarea', 'description', t('page_description'), array('cols' => 50, 'rows' => 5)); $form->addElement('textarea', 'keywords', t('page_keywords'), array('cols' => 50, 'rows' => 5)); $form->addElement('select', 'searcheable', t('page_search'), array(), array(0 => t('no'), 1 => t('yes'))); $form->addElement('hidden', 'content_id'); $form->addElement('hidden', 'parent_id'); $form->addElement('hidden', 'language_id'); // parent of new page is 0 by default $form->setDefault('content_id', 0); $form->setDefault('parent_id', 0); $form->setDefault('language_id', $languages->adminDefault()); // add form rules $form->addRule('reference', 'required', t('reference_required')); $form->addRule('reference', 'alphanumeric', t('reference_alphanumeric')); $form->addRule('reference', 'maxwords', t('reference_maxwords'), 1); $form->addRule('reference', 'maxlength', t('reference_maxlength'), 100); $form->addRule('title', 'required', t('title_required')); $form->addRule('title', 'maxlength', t('title_maxlength'), 255); $form->addRule('content_id', 'required', t('content_id_required')); $form->addRule('content_id', 'numeric', t('content_id_numeric')); $form->addRule('parent_id', 'required', t('parent_id_required')); $form->addRule('parent_id', 'numeric', t('parent_id_numeric')); $form->addRule('html', 'maxlength', t('html_maxlength'), 50000); $form->addRule('xhtml', 'maxlength', t('xhtml_maxlength'), 50000); $form->addRule('template_pack', 'in_array', t('template_pack_invalid'), array(0, 1)); $form->addRule('template', 'in_array', t('template_invalid'), array_keys($templates->visitors_templates())); $form->addRule('metatags', 'in_array', t('metatags_invalid'), array(0, 1)); $form->addRule('description', 'maxlength', t('description_maxlength'), 2000); $form->addRule('keywords', 'maxlength', t('keywords_maxlength'), 2000); return $form; }