function printForm($data = array()) { foreach (array('name', 'email', 'copy_me', 'subject', 'text') as $value) { if (!isset($data[$value])) { $data[$value] = ''; } } $form = new HTML_QuickForm2('contect', 'post', array('action' => '/account-mail.php?handle=' . htmlspecialchars($_GET['handle']))); $form->removeAttribute('name'); // Set defaults for the form elements $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('name' => htmlspecialchars($data['name']), 'email' => htmlspecialchars($data['email']), 'copy_me' => htmlspecialchars($data['copy_me']), 'subject' => htmlspecialchars($data['subject']), 'text' => htmlspecialchars($data['text'])))); $form->addElement('text', 'name', array('required' => 'required'))->setLabel('Y<span class="accesskey">o</span>ur Name:', 'size="40" accesskey="o"'); $form->addElement('email', 'email', array('required' => 'required'))->setLabel('Email Address:'); $form->addElement('checkbox', 'copy_me')->setLabel('CC me?:'); $form->addElement('text', 'subject', array('required' => 'required', 'size' => '80'))->setLabel('Subject:'); $form->addElement('textarea', 'text', array('cols' => 80, 'rows' => 10, 'required' => 'required'))->setLabel('Text:'); if (!auth_check('pear.dev')) { $numeralCaptcha = new Text_CAPTCHA_Numeral(); $form->addElement('number', 'captcha', array('maxlength' => 4, 'required' => 'required'))->setLabel("What is " . $numeralCaptcha->getOperation() . '?'); $_SESSION['answer'] = $numeralCaptcha->getAnswer(); } $form->addElement('submit', 'submit')->setLabel('Send Email'); print $form; }
echo 'No karma yet'; } else { $table = new HTML_Table('style="width: 90%"'); $table->setCaption('Karma levels for ' . htmlspecialchars($handle), 'style="background-color: #CCCCCC;"'); $table->addRow(array("Level", "Added by", "Added at", "Remove"), null, 'th'); foreach ($user_karma as $item) { $remove = sprintf("karma.php?action=remove&handle=%s&level=%s", htmlspecialchars($handle), htmlspecialchars($item['level'])); $table->addRow(array(htmlspecialchars($item['level']), htmlspecialchars($item['granted_by']), htmlspecialchars($item['granted_at']), make_link($remove, make_image("delete.gif"), false, 'onclick="javascript:return confirm(\'Do you really want to remove the karma level ' . htmlspecialchars($item['level']) . '?\');"'))); } echo $table->toHTML(); } echo "<br /><br />"; $table = new HTML_Table('style="width: 100%"'); $table->setCaption("Grant karma to " . htmlspecialchars($handle), 'style="background-color: #CCCCCC;"'); $form = new HTML_QuickForm2('karma_grant', 'post', array('action' => 'karma.php?action=grant')); $form->removeAttribute('name'); $form->addElement('text', 'level')->setLabel('Level: '); $form->addElement('hidden', 'handle')->setValue(htmlspecialchars($handle)); $form->addElement('submit', 'submit')->setLabel('Submit Changes'); $csrf_token_value = create_csrf_token($csrf_token_name); $form->addElement('hidden', $csrf_token_name)->setValue($csrf_token_value); $table->addRow(array((string) $form)); echo $table->toHTML(); } echo "<p> </p><hr />"; $table = new HTML_Table('style="width: 90%"'); $table->setCaption("Karma Statistics", 'style="background-color: #CCCCCC;"'); if (!empty($_GET['a']) && $_GET['a'] == "details" && !empty($_GET['level'])) { $table->addRow(array('Handle', 'Granted'), null, 'th'); foreach ($karma->getUsers($_GET['level']) as $user) { $detail = sprintf("Granted by <a href=\"/user/%s\">%s</a> on %s", htmlspecialchars($user['granted_by']), htmlspecialchars($user['granted_by']), htmlspecialchars($user['granted_at']));
public function testIdAndMethodAreReadonly() { $form = new HTML_QuickForm2('foo', 'get'); try { $form->removeAttribute('id'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { try { $form->setAttribute('method', 'post'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { try { $form->setId('newId'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { return; } } } $this->fail('Expected HTML_QuickForm2_InvalidArgumentException was not thrown'); }