本文整理汇总了PHP中HTML_QuickForm::addFormRule方法的典型用法代码示例。如果您正苦于以下问题:PHP HTML_QuickForm::addFormRule方法的具体用法?PHP HTML_QuickForm::addFormRule怎么用?PHP HTML_QuickForm::addFormRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTML_QuickForm
的用法示例。
在下文中一共展示了HTML_QuickForm::addFormRule方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute() {
$request = $this->getContext()->getRequest();
$postLoginUser = $request->getParameter('user');
$postLoginId = $postLoginUser['id'];
$id = $request->getParameter('id');
$login = $this->getContext()->getUser()->getAttribute('Login');
$loginRole = $this->getLoginRole();
if ($loginRole == 'editor'){
if ($id != $login->id && $postLoginId != $login->id){
$this->log("Unauthorized attempt edit login record. Login id: $id, user name: ". $login->name);
$this->getContext()->getController()->forward('Default', "Secure");
}
}
// $this->checkAdminAuth();
if($request->getParameter('cancel')) {
if ($loginRole == 'admin'){
$this->getContext()->getController()->forward('Default', "ListLogin");
} else {
header("Location:Search?searchFor=Member");
}
return View::NONE;
}
$form = new HTML_QuickForm("loginForm", 'post');
$loginDao = new BaseDao("Login");
$affDao = new BaseDao("Affiliate");
if ($id){
$user = $loginDao->get($id);
$this->log("Editing login: ".$user->login." ,name: ".$user->name);
$this->log("Editing login: ".$user->login." ,name: ".$user->name, true);
$affiliate = $affDao->getPattern();
$affiliate->editor = $user->id;
$currentAffs = $affDao->search($affiliate);
$affIds = $this->getListOfCertainFieldValues($currentAffs, 'id');
$form->setDefaults(array('user' => (array) $user,
"password2" => $user->password,
"affiliates" => $affIds));
} else{
$this->log("Creating new login.", true);
$user = $loginDao->getPattern();
}
$request->setAttribute('user', $user);
$roleDao = new BaseDao("Role");
$roles = $this->prepareDropdown($roleDao->search(), 'id', 'name');
$affs = $this->prepareDropdown($affDao->searchWhereWithOrder($affDao->getPattern(), "1=1", 'name'), 'id', 'name');
$form->addElement("text", "user[name]", "Name:", array('size' => 50, "maxlength" => 255));
$form->addElement("text", "user[login]", "Login:", array('size' => 50, "maxlength" => 255));
$form->addElement("password", "user[password]", "Password:", array('size' => 50, "maxlength" => 255));
$form->addElement("password", "password2", "Repeat Password:", array('size' => 50, "maxlength" => 255));
$form->addElement('text', "user[email]", 'Email:', array('size' => 50, "maxlength" => 255));
$form->addElement('select', "user[roleFid]", "User Role:", $roles);
$form->addElement('select', "affiliates", "Affiliate:", $affs, array('multiple' => 'multiple', 'id' => "affDropdown") );
$form->addElement('checkbox', "user[nationalOfficer]", "National Officer:", "", array());
$element =& $form->getElement("affiliates");
$element->setSize(5);
if ($loginRole != 'admin') $element->freeze();
$form->addElement('hidden', 'user[id]');
$form->addElement("submit", null, "Save Changes");
$form->addElement("submit", 'cancel', "Cancel");
$form->addRule("user[name]", "Please enter your name.", 'required', null);
$form->addRule("user[login]", "Login can't be blank.", 'required', null);
$form->addRule("user[password]", "You haven't entered password.", 'required', null);
$form->addRule("user[email]", "Please enter your email.", 'required', null);
$form->addRule("user[email]", "Please enter valid email.", 'email', null);
$form->addFormRule(array(&$this, "validatePassword"));
$form->addFormRule(array(&$this, "checkEmail"));
$form->addFormRule(array(&$this, "max5admins"));
if (!$form->validate()) {
$request->setAttribute("editLoginForm", $form->toHtml());
//.........这里部分代码省略.........
示例2: _validate
private function _validate()
{
if ($this->action == TIP_FORM_ACTION_DELETE || $this->action == TIP_FORM_ACTION_CUSTOM) {
// Special case: GET driven form
$this->_form->freeze();
return TIP::getGet('process', 'int') == 1;
}
// Add element and form rules
isset($this->validator) && $this->_form->addFormRule($this->validator);
foreach (array_keys($this->fields) as $id) {
if ($this->_form->elementExists($id)) {
$this->_addGuessedRules($id);
$this->_addCustomRules($id);
}
}
$stage_id = $this->id . '.stage';
$last_stage = HTTP_Session2::get($stage_id);
if (!$this->_form->isSubmitted() || isset($last_stage) && $last_stage < $this->_stage) {
HTTP_Session2::set($stage_id, $this->_stage);
$valid = false;
} elseif (is_null($last_stage)) {
// No last stage defined
TIP::notifyError('double');
$valid = null;
} else {
// Validation
$this->_form->applyFilter('__ALL__', array('TIP', 'extendedTrim'));
$valid = $this->_form->validate();
}
// Perform uploads (if needed)
if (is_callable(array('HTML_QuickForm_attachment', 'doUploads'))) {
HTML_QuickForm_attachment::doUploads($this->_form);
}
return $valid;
}
示例3: buildWriteForm
function buildWriteForm($options) {
global $fyr_values, $fyr_postcode, $fyr_who, $fyr_type;
global $fyr_representative, $fyr_voting_area, $fyr_date;
global $fyr_postcode_editable, $fyr_group_msg, $fyr_valid_reps;
global $rep_text, $cobrand, $cocode;
$form_action = cobrand_url($cobrand, '/write', $cocode);
$form = new HTML_QuickForm('writeForm', 'post', $form_action);
if ($fyr_voting_area['name']=='United Kingdom')
$fyr_voting_area['name'] = 'House of Lords';
$write_header = '';
if ($options['include_write_header']){
$write_header = "<strong>Now Write Your Message:</strong> <small>(* means required)</small><br><br>";
}
if ($options['include_fao']){
$write_header = '<strong>For the attention of:</strong>';
}
$stuff_on_left = <<<END
<div class="letter-header">
${write_header}
${rep_text}
<span>${fyr_voting_area['name']}</span>
<span>$fyr_date</span>
</div>
END;
// special formatting for letter-like code, TODO: how do this properly with QuickHtml?
if ($options['table_layout']){
$form->addElement("html", "<tr><td valign=\"top\">$stuff_on_left</td><td align=\"right\">\n<table>"); // CSSify
} else {
$form->addElement("html", "<div class=\"highlight\">$stuff_on_left<ul class=\"data-input\">");
}
$form->addElement('text', 'name', "Your name:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
$form->addRule('name', 'Please enter your name', 'required', null, null);
$form->applyFilter('name', 'trim');
$form->addElement('text', 'writer_address1', "Address 1:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
$form->addRule('writer_address1', 'Please enter your address', 'required', null, null);
$form->applyFilter('writer_address1', 'trim');
$form->addElement('text', 'writer_address2', "Address 2:", array('size' => 20, 'maxlength' => 255));
$form->applyFilter('writer_address2', 'trim');
$form->addElement('text', 'writer_town', "Town/City:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
$form->addRule('writer_town', 'Please enter your town/city', 'required', null, null);
$form->applyFilter('writer_town', 'trim');
# Call it state so that Google Toolbar (and presumably others) can auto-fill.
$form->addElement('text', 'state', 'County:', array('size' => 20, 'maxlength' => 255));
$form->applyFilter('state', 'trim');
if ($fyr_postcode_editable) {
// House of Lords
$form->addElement('text', 'pc', "UK postcode:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
$form->addRule('pc', 'Please enter a UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', 'required', null, null);
$form->addRule('pc', 'Choose a valid UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', new RulePostcode(), null, null);
$form->applyFilter('pc', 'trim');
} else {
// All other representatives (postcode fixed as must be in constituency)
$form->addElement('static', 'staticpc', 'UK postcode:', htmlentities($fyr_postcode));
}
$form->addElement('text', 'writer_email', "Your email:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
$form->addRule('writer_email', 'Please enter your email address', 'required', null, null);
$invalid_email_message = cobrand_invalid_email_message($cobrand);
if (!$invalid_email_message) {
$invalid_email_message = 'Choose a valid email address';
}
$form->addRule('writer_email', $invalid_email_message, 'email', null, null);
$form->applyFilter('writer_email', 'trim');
$form->addElement('text', 'writer_email2', "Confirm email:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
$form->addRule('writer_email2', 'Please re-enter your email address', 'required', null, null);
$form->applyFilter('writer_email2', 'trim');
$form->addFormRule('compare_email_addrs');
/* add additional text explaining why we ask for email address twice? */
# $form->addElement("html", "</td><td colspan=2><p style=\"margin-top: 0em; margin-bottom: -0.2em\"><em style=\"font-size: 75%\">Optional, to let your {$fyr_voting_area['rep_name']} contact you more easily:</em>"); // CSSify
$form->addElement('text', 'writer_phone', "Phone:", array('size' => 20, 'maxlength' => 255));
$form->applyFilter('writer_phone', 'trim');
// special formatting for letter-like code, TODO: how do this properly with QuickHtml?
if ($options['table_layout']){
$form->addElement("html", "</table>\n</td></tr>");
} else {
$form->addElement("html", "</ul>");
}
$form->addElement('textarea', 'body', null, array('rows' => 15, 'cols' => 62));
$form->addRule('body', 'Please enter your message', 'required', null, null);
$form->addRule('body', 'Please enter your message', new RuleAlteredBodyText(), null, null);
$form->addRule('body', 'Please sign at the bottom with your name, or alter the "Yours sincerely" signature', new RuleSigned(), null, null);
$form->addRule('body', 'Your message is a bit too long for us to send', 'maxlength', OPTION_MAX_BODY_LENGTH);
if (!$options['table_layout']){
//.........这里部分代码省略.........
示例4: buildWriteForm
function buildWriteForm($options)
{
global $fyr_values, $stash;
global $fyr_voting_area;
global $cobrand, $cocode;
$form_action = cobrand_url($cobrand, '/write', $cocode);
$form = new HTML_QuickForm('writeForm', 'post', $form_action);
if ($fyr_voting_area['name'] == 'United Kingdom') {
$fyr_voting_area['name'] = 'House of Lords';
}
$write_header = '';
$form->addElement('textarea', 'body', null, array('class' => 'message'));
$form->addRule('body', 'Please enter your message', 'required', null, null);
$form->addRule('body', 'Please enter your message', new RuleAlteredBodyText(), null, null);
$form->addRule('body', 'Please sign at the bottom with your name, or alter the "Yours sincerely" signature', new RuleSigned(), null, null);
$form->addRule('body', 'Your message is a bit too long for us to send', 'maxlength', OPTION_MAX_BODY_LENGTH);
$form->addElement('html', '<div class="row">');
$form->addElement('html', '<fieldset class="large-6 columns">');
$form->addElement('html', '<legend>About You</legend>');
$form->addElement('text', 'name', "Your name", array('required' => 'required', 'maxlength' => 255));
$form->addRule('name', 'Please enter your name', 'required', null, null);
$form->applyFilter('name', 'trim');
$form->addElement('text', 'writer_email', "Your email", array('required' => 'required', 'maxlength' => 255));
$form->addRule('writer_email', 'Please enter your email address', 'required', null, null);
$invalid_email_message = cobrand_invalid_email_message($cobrand);
if (!$invalid_email_message) {
$invalid_email_message = 'Choose a valid email address';
}
$form->addRule('writer_email', $invalid_email_message, 'email', null, null);
$form->applyFilter('writer_email', 'trim');
$form->addElement('text', 'writer_email2', "Confirm email", array('required' => 'required', 'maxlength' => 255));
$form->addRule('writer_email2', 'Please re-enter your email address', 'required', null, null);
$form->applyFilter('writer_email2', 'trim');
$form->addFormRule('compare_email_addrs');
$form->updateElementAttr(array('writer_email', 'writer_email2'), array('type' => 'email'));
$form->addElement('text', 'writer_phone', 'Phone <span class="optional-text">optional</span>', array('maxlength' => 255));
$form->applyFilter('writer_phone', 'trim');
$form->addElement("html", "</fieldset>");
$form->addElement("html", '<fieldset class="large-6 columns">');
$form->addElement("html", '<legend>Your Address</legend>');
$form->addElement('text', 'writer_address1', "Address Line 1", array('required' => 'required', 'maxlength' => 255));
$form->addRule('writer_address1', 'Please enter your address', 'required', null, null);
$form->applyFilter('writer_address1', 'trim');
$form->addElement('text', 'writer_address2', 'Address Line 2 <span class="optional-text">optional</span>', array('maxlength' => 255));
$form->applyFilter('writer_address2', 'trim');
$form->addElement('text', 'writer_town', "Town/City", array('required' => 'required', 'maxlength' => 255));
$form->addRule('writer_town', 'Please enter your town/city', 'required', null, null);
$form->applyFilter('writer_town', 'trim');
$form->addElement('html', '<div class="row">');
$form->addElement('html', '<div class="small-8 columns">');
# Call it state so that Google Toolbar (and presumably others) can auto-fill.
$form->addElement('text', 'state', 'County <span class="optional-text">optional</span>', array('maxlength' => 255));
$form->applyFilter('state', 'trim');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="small-4 columns">');
if (is_postcode_editable($fyr_voting_area['type'])) {
// House of Lords
$form->addElement('text', 'pc', "UK postcode", array('required' => 'required', 'maxlength' => 8));
$form->addRule('pc', 'Please enter a UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', 'required', null, null);
$form->addRule('pc', 'Please enter a valid UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', new RulePostcode(), null, null);
$form->applyFilter('pc', 'trim');
} else {
// All other representatives (postcode fixed as must be in constituency)
$form->addElement('text', 'staticpc', "UK postcode", array('disabled' => 'disabled', 'value' => htmlentities($fyr_values['pc'])));
}
$form->addElement('html', '</div>');
$form->addElement('html', '</div>');
$form->addElement("html", "</fieldset>");
$form->addElement('html', '</div>');
# close div.row
$form->addElement("html", '<fieldset class="last"><legend>Ready?</legend>');
add_all_variables_hidden($form, $fyr_values, $options);
$preview_text = cobrand_preview_text($cobrand);
if (!$preview_text) {
$preview_text = "When you’re ready to send your message click the button below. You’ll get a chance to read through it again to check for problems before we send it.";
}
$preview_button_text = cobrand_preview_button_text($cobrand);
if (!$preview_button_text) {
$preview_button_text = 'Preview and send';
}
$form->addElement('html', "<p class=\"action\" id=\"preview-submit\">{$preview_text}</p>");
$form->addElement('submit', 'submitPreview', $preview_button_text, array('class' => 'button radius success'));
$form->addElement("html", "</fieldset>");
return $form;
}