本文整理汇总了PHP中Horde_Form::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Form::validate方法的具体用法?PHP Horde_Form::validate怎么用?PHP Horde_Form::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Form
的用法示例。
在下文中一共展示了Horde_Form::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate(&$vars)
{
if (!Whups::hasPermission($this->_queue, 'queue', Horde_Perms::DELETE)) {
$this->setError('yesno', _("Permission Denied."));
}
return parent::validate($vars);
}
示例2: validate
public function validate(&$vars)
{
if (Whups::hasPermission($this->_queue, 'queue', Horde_Perms::DELETE)) {
$this->_warn->setDefault('<span class="horde-form-error">' . _("Permission Denied.") . '</span>');
}
return parent::validate($vars);
}
示例3: validate
public function validate(&$vars, $canAutoFill = false)
{
global $conf;
if (!parent::validate($vars, $canAutoFill)) {
if (!$GLOBALS['registry']->getAuth() && !empty($conf['guests']['captcha'])) {
$vars->remove('captcha');
$this->removeVariable($varname = 'captcha');
$this->insertVariableBefore('newcomment', _("Spam protection"), 'captcha', 'figlet', true, null, null, array(Whups::getCAPTCHA(true), $conf['guests']['figlet_font']));
}
return false;
}
return true;
}
示例4: validateDeleteForm
/**
* Function to validate any delete form input.
*
* @param TODO $info TODO
*
* @return mixed If the delete button confirmation has been pressed return
* true, if any other submit button has been pressed return
* false. If form did not validate return null.
*/
public function validateDeleteForm(&$info)
{
$form_submit = $this->_vars->get('submitbutton');
if ($form_submit == Horde_Core_Translation::t("Delete")) {
if ($this->_form->validate($this->_vars)) {
$this->_form->getInfo($this->_vars, $info);
return true;
}
} elseif (!empty($form_submit)) {
return false;
}
return null;
}
示例5: run
/**
* Expects:
* $vars
* $registry
* $notification
*/
public function run()
{
extract($this->_params, EXTR_REFS);
/* Set up the form variables and the form. */
$form_submit = $vars->get('submitbutton');
$channel_id = $vars->get('channel_id');
try {
$channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($channel_id);
} catch (Exception $e) {
Horde::log($e, 'ERR');
$notification->push(_("Invalid channel specified for deletion."), 'horde.message');
Horde::url('channels')->redirect();
exit;
}
/* If not yet submitted set up the form vars from the fetched channel. */
if (empty($form_submit)) {
$vars = new Horde_Variables($channel);
}
/* Check permissions and deny if not allowed. */
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id)) {
$notification->push(_("You are not authorised for this action."), 'horde.warning');
throw new Horde_Exception_AuthenticationFailure();
}
$title = sprintf(_("Delete News Channel \"%s\"?"), $vars->get('channel_name'));
$form = new Horde_Form($vars, $title);
$form->setButtons(array(_("Delete"), _("Do not delete")));
$form->addHidden('', 'channel_id', 'int', true, true);
$msg = _("Really delete this News Channel? All stories created in this channel will be lost!");
$form->addVariable($msg, 'confirm', 'description', false);
if ($form_submit == _("Delete")) {
if ($form->validate($vars)) {
$form->getInfo($vars, $info);
try {
$delete = $GLOBALS['injector']->getInstance('Jonah_Driver')->deleteChannel($info);
$notification->push(_("The channel has been deleted."), 'horde.success');
Horde::url('channels')->redirect();
exit;
} catch (Exception $e) {
$notification->push(sprintf(_("There was an error deleting the channel: %s"), $e->getMessage()), 'horde.error');
}
}
} elseif (!empty($form_submit)) {
$notification->push(_("Channel has not been deleted."), 'horde.message');
Horde::url('channels')->redirect();
exit;
}
$GLOBALS['page_output']->header(array('title' => $title));
$notification->notify(array('listeners' => 'status'));
$form->renderActive(null, $vars, Horde::selfUrl(), 'post');
$GLOBALS['page_output']->footer();
}
示例6: display
/**
* Display form
*
* @param integer $form_id Form id dispaly
* @param string $target_url Target url to link form to
*/
public function display($form_id, $target_url = null)
{
/* Get the stored form information from the backend. */
try {
$form_info = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create()->getForm($form_id, Horde_Perms::READ);
} catch (Horde_Exception $e) {
throw new Ulaform_Exception($e->getMessage());
}
if (!empty($form_info['form_params']['language'])) {
Horde_Nls::setLanguageEnvironment($form_info['form_params']['language']);
}
$vars = Horde_Variables::getDefaultVariables();
$vars->set('form_id', $form_id);
$form = new Horde_Form($vars);
$form->addHidden('', 'form_id', 'int', false);
$form->addHidden('', 'user_uid', 'text', false);
$form->addHidden('', 'email', 'email', false);
$vars->set('user_uid', $GLOBALS['registry']->getAuth());
$vars->set('email', $GLOBALS['prefs']->getValue('from_addr'));
try {
$fields = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create()->getFields($form_id);
} catch (Ulaform_Exception $e) {
throw new Ulaform_Exception($e->getMessage());
}
foreach ($fields as $field) {
/* In case of these types get array from stringlist. */
if ($field['field_type'] == 'link' || $field['field_type'] == 'enum' || $field['field_type'] == 'multienum' || $field['field_type'] == 'mlenum' || $field['field_type'] == 'radio' || $field['field_type'] == 'set' || $field['field_type'] == 'sorter') {
$field['field_params']['values'] = Ulaform::getStringlistArray($field['field_params']['values']);
}
/* Setup the field with all the parameters. */
$form->addVariable($field['field_label'], $field['field_name'], $field['field_type'], $field['field_required'], $field['field_readonly'], $field['field_desc'], $field['field_params']);
}
/* Check if submitted and validate. */
$result = array('title' => $form_info['form_name']);
if ($form->validate()) {
$form->getInfo(null, $info);
try {
$GLOBALS['ulaform_driver']->submitForm($info);
return true;
} catch (Horde_Exception $e) {
throw new Ulaform_Exception(sprintf(_("Error submitting form. %s."), $e->getMessage()));
}
}
if (is_null($target_url)) {
$target_url = Horde::selfUrl(true);
}
Horde::startBuffer();
$form->renderActive(null, null, $target_url, 'post', 'multipart/form-data');
return array('title' => $form_info['form_name'], 'form' => Horde::endBuffer());
}
示例7: _content
protected function _content()
{
$vars = Horde_Variables::getDefaultVariables();
$formname = $vars->get('formname');
$done = false;
$form = new Horde_Form($vars);
$fields = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create()->getFields($this->_params['form_id']);
foreach ($fields as $field) {
/* In case of these types get array from stringlist. */
if ($field['field_type'] == 'link' || $field['field_type'] == 'enum' || $field['field_type'] == 'multienum' || $field['field_type'] == 'radio' || $field['field_type'] == 'set' || $field['field_type'] == 'sorter') {
$field['field_params']['values'] = Ulaform::getStringlistArray($field['field_params']['values']);
}
/* Setup the field with all the parameters. */
$form->addVariable($field['field_label'], $field['field_name'], $field['field_type'], $field['field_required'], $field['field_readonly'], $field['field_desc'], $field['field_params']);
}
if ($formname) {
$form->validate($vars);
if ($form->isValid() && $formname) {
$form->getInfo($vars, $info);
$info['form_id'] = $this->_params['form_id'];
try {
$submit = $GLOBALS['ulaform_driver']->submitForm($info);
$GLOBALS['notification']->push(_("Form submitted successfully."), 'horde.success');
$done = true;
} catch (Horde_Exception $e) {
$GLOBALS['notification']->push(sprintf(_("Error submitting form. %s."), $e->getMessage()), 'horde.error');
}
}
}
/* Render active or inactive, depending if submitted or
* not. */
$render_type = $done ? 'renderInactive' : 'renderActive';
/* Render the form. */
$renderer = new Horde_Form_Renderer();
$renderer->showHeader(false);
Horde::startBuffer();
$form->{$render_type}($renderer, $vars, Horde::selfUrl(true), 'post');
return Horde::endBuffer();
}
示例8: foreach
foreach ($extra as $field_name => $field) {
$readonly = isset($field['readonly']) ? $field['readonly'] : null;
$desc = isset($field['desc']) ? $field['desc'] : null;
$field_params = isset($field['params']) ? $field['params'] : array();
$addForm->addVariable($field['label'], 'extra[' . $field_name . ']', $field['type'], $field['required'], $readonly, $desc, $field_params);
}
}
} catch (Horde_Exception_HookNotSet $e) {
}
if (empty($extra)) {
$addForm->addVariable(_("Username"), 'user_name', 'text', true);
$addForm->addVariable(_("Password"), 'password', 'passwordconfirm', false, false, _("type the password twice to confirm"));
}
switch ($vars->form) {
case 'add':
$addForm->validate($vars);
if ($addForm->isValid() && $vars->get('formname') == 'adduser') {
$addForm->getInfo($vars, $info);
if (empty($info['user_name']) && isset($info['extra']['user_name'])) {
$info['user_name'] = $info['extra']['user_name'];
}
if (empty($info['password']) && isset($info['extra']['password'])) {
$info['password'] = $info['extra']['password'];
}
if (empty($info['user_name'])) {
$notification->push(_("You must specify the username to add."), 'horde.error');
} elseif ($auth->exists($info['user_name'])) {
$notification->push(sprintf(_("The user \"%s\" already exists."), $info['user_name']), 'horde.error');
} else {
$credentials = array('password' => $info['password']);
if (isset($info['extra'])) {
示例9: catch
if ($vars->get('email') == $email) {
$can_validate = true;
$form->setButtons(_("Reset Password"));
$question = $prefs->getValue('security_question');
$form->addVariable($question, 'question', 'description', false);
$form->addVariable(_("Answer"), 'answer', 'text', true);
if (!$question) {
$notification->push(_("No security question has been set. Please contact your administrator."), 'horde.error');
$registry->getServiceLink('login')->add('url', $vars->url)->redirect();
}
} else {
$notification->push(_("Incorrect username or alternate address. Try again or contact your administrator if you need further help."), 'horde.error');
}
}
/* Validate the form. */
if ($can_validate && $form->validate($vars)) {
$form->getInfo($vars, $info);
/* Fetch values from prefs for selected user. */
$answer = $prefs->getValue('security_answer');
/* Check the given values witht the prefs stored ones. */
if ($email == $info['email'] && strtolower($answer) == strtolower($info['answer'])) {
/* Info matches, so reset the password. */
try {
$password = $auth->resetPassword($info['username']);
$success = true;
} catch (Horde_Exception $e) {
$notification->push($e);
$success = false;
}
$mail = new Horde_Mime_Mail(array('body' => sprintf(_("Your new password for %s is: %s"), $registry->get('name', 'horde'), $password), 'charset' => 'UTF-8', 'From' => empty($conf['auth']['resetpassword_from']) ? $email : $conf['auth']['resetpassword_from'], 'To' => $email, 'Subject' => _("Your password has been reset")));
try {
示例10: isset
/* Check if the submitted field type has extra parameters and set them up. */
$field_type = $vars->get('field_type');
$available_params = Ulaform::getFieldParams($field_type);
if (!is_null($vars->get('formname')) && $vars->get($v->getVarName()) != $vars->get('__old_' . $v->getVarName()) && !empty($available_params)) {
$notification->push(_("This field type has extra parameters."), 'horde.message');
}
foreach ($available_params as $name => $param) {
$field_id = 'field_params[' . $name . ']';
$param['required'] = isset($param['required']) ? $param['required'] : null;
$param['readonly'] = isset($param['readonly']) ? $param['readonly'] : null;
$param['desc'] = isset($param['desc']) ? $param['desc'] : null;
$fieldform->addVariable($param['label'], $field_id, $param['type'], $param['required'], $param['readonly'], $param['desc']);
}
/* Set the current field type to the old field type var. */
$vars->set('old_field_type', $field_type);
if ($fieldform->validate($vars)) {
/* Save field if valid and the current and old field type match. */
$fieldform->getInfo($vars, $info);
try {
$save_field = $injector->getInstance('Ulaform_Factory_Driver')->create()->saveField($info);
$notification->push(_("Field saved."), 'horde.success');
Horde::url('fields.php', true)->add('form_id', $info['form_id'])->redirect();
} catch (Horde_Exception $e) {
$notification->push(sprintf(_("Error saving field. %s."), $e->getMessage()), 'horde.error');
}
}
/* Get a field list. */
try {
$fields_list = $ulaform_driver->getFieldsList($form_id);
if (empty($fields_list)) {
/* Show a warning if no fields present. */
示例11: isset
$param['readonly'] = isset($param['readonly']) ? $param['readonly'] : false;
$param['desc'] = isset($param['desc']) ? $param['desc'] : null;
$param['params'] = isset($param['params']) ? $param['params'] : null;
$form->addVariable($param['label'], 'form_params[' . $id . ']', $param['type'], $param['required'], $param['readonly'], $param['desc'], $param['params']);
}
}
/* Set default language for the form. */
$v = $form->addVariable(_("Default language"), 'form_params[language]', 'enum', false, false, null, array($registry->nlsconfig->languages, _("-- default configured --")));
$v->setOption('htmlchars', true);
/* TODO: set up Ulaform to insert any javascript saved here into the form. */
$v = $form->addVariable(_("Javascript to execute on form \"submit\":"), 'form_onsubmit', 'longtext', false, false, null, array(3, 40));
$v->setHelp('on-submit');
/* Set up the action choice fields. */
$vars->set('old_form_action', $form_action);
if ($formname && !$changed_action) {
$form->validate($vars);
if ($form->isValid()) {
$form->getInfo($vars, $info);
try {
$form_id = $ulaform_driver->saveForm($info);
$notification->push(_("Form details saved."), 'horde.success');
Horde::url('forms.php', true)->redirect();
} catch (Ulaform_Exception $e) {
$notification->push(sprintf(_("Error saving form. %s."), $e->getMessage()), 'horde.error');
}
}
}
/* Render the form. */
$view = new Horde_View(array('templatePath' => ULAFORM_TEMPLATES));
Horde::startBuffer();
$form->renderActive(new Horde_Form_Renderer(), $vars, Horde::url('edit.php'), 'post');
示例12: array
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('ulaform', array('admin' => true));
$delvars = Horde_Variables::getDefaultVariables();
$form_id = $delvars->get('form_id');
$form_submit = $delvars->get('submitbutton');
/* Set up the forms. */
$ulaform_driver = $injector->getInstance('Ulaform_Factory_Driver')->create();
$viewvars = new Horde_Variables($ulaform_driver->getForm($form_id));
$viewform = new Horde_Form($viewvars, _("Form Details"));
$delform = new Horde_Form($delvars, _("Delete this form?"));
$viewform->addVariable(_("Name"), 'form_name', 'text', false);
$viewform->addVariable(_("Action"), 'form_action', 'email', false);
$delform->setButtons(array(_("Delete"), _("Do not delete")));
$delform->addHidden('', 'form_id', 'int', true);
if ($form_submit == _("Delete")) {
$delform->validate($delvars);
if ($delform->isValid()) {
$delform->getInfo($delvars, $info);
try {
$deleteform = $ulaform_driver->deleteForm($info['form_id']);
$notification->push(_("Form deleted."), 'horde.success');
Horde::url('forms.php', true)->redirect();
} catch (Ulaform_Exception $e) {
$notification->push(sprintf(_("Error deleting form. %s."), $e->getMessage()), 'horde.error');
}
}
} elseif (!empty($form_submit)) {
$notification->push(_("Form has not been deleted."), 'horde.message');
Horde::url('forms.php', true)->redirect();
}
/* Render the form. */
示例13: run
public function run()
{
extract($this->_params, EXTR_REFS);
$form_submit = $vars->get('submitbutton');
$channel_id = $vars->get('channel_id');
$story_id = $vars->get('id');
/* Driver */
$driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
/* Fetch the channel details, needed for later and to check if valid
* channel has been requested. */
try {
$channel = $driver->getChannel($channel_id);
} catch (Exception $e) {
$notification->push(sprintf(_("Story editing failed: %s"), $e->getMessage()), 'horde.error');
Horde::url('channels/index.php', true)->redirect();
exit;
}
/* Check permissions. */
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id)) {
$notification->push(_("You are not authorised for this action."), 'horde.warning');
throw new Horde_Exception_AuthenticationFailure();
}
try {
$story = $driver->getStory($channel_id, $story_id);
} catch (Exception $e) {
$notification->push(_("No valid story requested for deletion."), 'horde.message');
Horde::url('channels/index.php', true)->redirect();
exit;
}
/* If not yet submitted set up the form vars from the fetched story. */
if (empty($form_submit)) {
$vars = new Horde_Variables($story);
}
$title = sprintf(_("Delete News Story \"%s\"?"), $vars->get('title'));
$form = new Horde_Form($vars, $title);
$form->setButtons(array(_("Delete"), _("Do not delete")));
$form->addHidden('', 'channel_id', 'int', true, true);
$form->addHidden('', 'id', 'int', true, true);
$form->addVariable(_("Really delete this News Story?"), 'confirm', 'description', false);
if ($form_submit == _("Delete")) {
if ($form->validate($vars)) {
$form->getInfo($vars, $info);
try {
$delete = $driver->deleteStory($info['channel_id'], $info['id']);
$notification->push(_("The story has been deleted."), 'horde.success');
Horde::url('stories/index.php', true)->add('channel_id', $channel_id)->setRaw(true)->redirect();
exit;
} catch (Exception $e) {
$notification->push(sprintf(_("There was an error deleting the story: %s"), $e->getMessage()), 'horde.error');
}
}
} elseif (!empty($form_submit)) {
$notification->push(_("Story has not been deleted."), 'horde.message');
$url = Horde::url('stories/index.php', true)->add('channel_id', $channel_id)->setRaw(true);
Horde::url('stories/index.php', true)->add('channel_id', $channel_id)->setRaw(true)->redirect();
exit;
}
$GLOBALS['page_output']->header(array('title' => $title));
$notification->notify(array('listeners' => 'status'));
$form->renderActive(null, $vars, Horde::url('stories/delete.php'), 'post');
$GLOBALS['page_output']->footer();
}
示例14: removeMessage
/**
* Allows other Horde apps to remove messages.
*
* The forum name is constructed by just the $forum_name variable
* under the data root 'agora.forums.<app>'. It is up to the apps
* themselves to make sure that the forum name is unique.
*
* @access private
*
* @param string $scope The application which is posting this message.
* @param string $forum_name The unique name for the forum.
* @param string $callback A callback method of the specified application
* that gets called to make sure that posting to
* this forum is allowed.
* @param array $params Any parameters for the forum message posting.
* <pre>
* message_id - An existing message to delete
* </pre>
* @param array $variables A hash with all variables of a submitted form
* generated by this method.
*
* @return mixed Returns either the rendered Horde_Form for posting a message
* or PEAR_Error object on error, or true in case of a
* successful post.
*/
public function removeMessage($scope, $forum_name, $callback, $params = array(), $variables = null)
{
global $registry;
/* Check if posting messages is allowed. */
$check = $registry->callByPackage($scope, $callback, array($forum_name));
if ($check instanceof PEAR_Error || !$check) {
return '';
}
/* Create a separate notification queue. */
$queue = Horde_Notification::singleton('agoraRemoveMessage');
$queue->attach('status');
/* Set up the forums object. */
$forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope);
$params['forum_id'] = $forums->getForumId($forum_name);
if (empty($params['forum_id'])) {
return PEAR::raiseError(sprintf(_("Forum %s does not exist."), $forum_name));
}
/* Set up the messages control object. */
$messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $params['forum_id']);
if ($messages instanceof PEAR_Error) {
PEAR::raiseError(sprintf(_("Could not delete the message. %s"), $messages->getMessage()));
}
/* Check delete permissions. */
if (!$messages->hasPermission(Horde_Perms::DELETE)) {
return PEAR::raiseError(sprintf(_("You don't have permission to delete messages in forum %s."), $params['forum_id']));
}
/* Get the message to be deleted. */
$message = $messages->getMessage($params['message_id']);
if ($message instanceof PEAR_Error) {
return PEAR::raiseError(sprintf(_("Could not delete the message. %s"), $message->getMessage()));
}
/* Set up the form. */
$vars = new Horde_Variables($variables);
$form = new Horde_Form($vars, sprintf(_("Delete \"%s\" and all replies?"), $message['message_subject']), 'delete_agora_message');
$form->setButtons(array(_("Delete"), _("Cancel")));
$form->addHidden('', 'forum_id', 'int', true);
$form->addHidden('', 'message_id', 'int', true);
if ($form->validate()) {
if ($vars->get('submitbutton') == _("Delete")) {
$result = $messages->deleteMessage($params['message_id']);
if ($result instanceof PEAR_Error) {
$queue->push(sprintf(_("Could not delete the message. %s"), $result->getMessage()), 'horde.error');
} else {
$queue->push(_("Message deleted."), 'horde.success');
$count = $messages->countMessages();
$registry->callByPackage($scope, $callback, array($forum_name, 'messages', $count));
}
} else {
$queue->push(_("Message not deleted."), 'horde.message');
}
Horde::startBuffer();
$queue->notify(array('listeners' => 'status'));
return Horde::endBuffer();
}
Horde::startBuffer();
$form->renderActive(null, null, null, 'post', null, false);
return Horde::endBuffer();
}
示例15: validate
public function validate(&$vars)
{
if (!$GLOBALS['registry']->getAuth()) {
$this->setError('_auth', _("Permission Denied."));
}
return parent::validate($vars);
}