本文整理汇总了PHP中Pieform::set_error方法的典型用法代码示例。如果您正苦于以下问题:PHP Pieform::set_error方法的具体用法?PHP Pieform::set_error怎么用?PHP Pieform::set_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pieform
的用法示例。
在下文中一共展示了Pieform::set_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export_validate
function export_validate(Pieform $form, $values)
{
global $SESSION;
if ($values['what'] == 'views') {
$viewchosen = false;
foreach ($values as $key => $value) {
if (substr($key, 0, 5) == 'view_' && $value) {
$viewchosen = true;
}
}
if (!$viewchosen) {
$form->set_error('what', '');
$SESSION->add_error_msg(get_string('youmustselectatleastoneviewtoexport', 'export'));
}
} else {
if ($values['what'] == 'collections') {
$viewchosen = false;
foreach ($values as $key => $value) {
if (substr($key, 0, 11) == 'collection_' && $value) {
$viewchosen = true;
}
}
if (!$viewchosen) {
$form->set_error('what', '');
$SESSION->add_error_msg(get_string('youmustselectatleastonecollectiontoexport', 'export'));
}
}
}
}
示例2: gwfontform_validate
function gwfontform_validate(Pieform $form, $values)
{
global $USER, $SESSION;
require_once 'file.php';
require_once 'uploadmanager.php';
$valid = false;
if ($values['gwfzipfile'] != null) {
$filetype = $values['gwfzipfile']['type'];
// Ensures that the correct file was chosen
$accepted = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/s-compressed');
foreach ($accepted as $mimetype) {
if ($mimetype == $filetype) {
$valid = true;
break;
}
}
// Safari and Chrome don't register zip mime types. Something better could be used here.
// Check if file extension, that is the last 4 characters in file name, equals '.zip'...
$valid = substr($values['gwfzipfile']['name'], -4) == '.zip' ? true : false;
if (!$valid) {
$form->set_error('gwfzipfile', get_string('notvalidzipfile', 'skin'));
}
// pass it through the virus checker
$um = new upload_manager('gwfzipfile');
if ($error = $um->preprocess_file()) {
$form->set_error($inputname, $error);
}
}
}
示例3: importeuropassform_validate
function importeuropassform_validate(Pieform $form, $values)
{
global $USER, $SESSION;
$filetype = $values['file']['type'];
if (!$filetype || $filetype != 'text/xml') {
$form->set_error('file', get_string('notvalidxmlfile', 'artefact.europass'));
}
// Check if at least one import option is checked...
$options = array();
if (!empty($values['identification'])) {
$options[] = 'identification';
}
if (!empty($values['application'])) {
$options[] = 'application';
}
if (!empty($values['workexperience'])) {
$options[] = 'workexperience';
}
if (!empty($values['education'])) {
$options[] = 'education';
}
if (!empty($values['languages'])) {
$options[] = 'languages';
}
if (!empty($values['skills'])) {
$options[] = 'skills';
}
if (!empty($values['additionalinfo'])) {
$options[] = 'additionalinfo';
}
if (empty($options)) {
$form->set_error('additionalinfo', get_string('nocheckedoptions', 'artefact.europass'));
}
}
示例4: forgotpass_validate
function forgotpass_validate(Pieform $form, $values)
{
// See if the user input an email address or a username. We favour email addresses
if (!$form->get_error('emailusername')) {
// Check if the user who associates to username or email address is using the external authentication
if (record_exists_sql('SELECT u.authinstance
FROM {usr} u INNER JOIN {auth_instance} ai ON (u.authinstance = ai.id)
WHERE (LOWER(u.email) = ? OR LOWER(u.username) = ?)
AND ((ai.authname != \'internal\') AND (ai.authname != \'none\'))', array_fill(0, 2, strtolower($values['emailusername'])))) {
$form->set_error('emailusername', get_string('forgotpassuserusingexternalauthentication', 'mahara', get_config('wwwroot') . 'contact.php'));
} else {
if (!($authinstance = get_field_sql('SELECT u.authinstance
FROM {usr} u INNER JOIN {auth_instance} ai ON (u.authinstance = ai.id)
WHERE (LOWER(u.email) = ? OR LOWER(u.username) = ?)
AND ai.authname = \'internal\'', array_fill(0, 2, strtolower($values['emailusername']))))) {
$form->set_error('emailusername', get_string('forgotpassnosuchemailaddressorusername'));
}
}
}
if ($form->get_error('emailusername')) {
return;
}
$authobj = AuthFactory::create($authinstance);
if (!method_exists($authobj, 'change_password')) {
die_info(get_string('cantchangepassword'));
}
}
示例5: addvariantform_validate
function addvariantform_validate(Pieform $form, $values)
{
global $USER, $SESSION;
require_once 'file.php';
require_once 'uploadmanager.php';
// Make sure they didn't hack the hidden variable to have the name of
// a font that doesn't exist
if (!record_exists('skin_fonts', 'name', $values['fontname'])) {
$form->set_error('fontname', get_string('nosuchfont', 'skin'));
}
$uploadfiles = array('fontfileEOT' => array('required' => true, 'suffix' => 'eot'), 'fontfileSVG' => array('required' => true, 'suffix' => 'svg'), 'fontfileTTF' => array('required' => true, 'suffix' => 'ttf'), 'fontfileWOFF' => array('required' => true, 'suffix' => 'woff'));
foreach ($uploadfiles as $inputname => $details) {
$um = new upload_manager($inputname, false, null, $details['required']);
if ($error = $um->preprocess_file()) {
$form->set_error($inputname, $error);
}
if ($details['suffix']) {
$reqext = ".{$details['suffix']}";
$fileext = substr($values[$inputname]['name'], -1 * strlen($reqext));
if ($fileext != $reqext) {
$form->set_error($inputname, get_string('notvalidfontfile', 'skin', strtoupper($details['suffix'])));
}
}
}
}
示例6: bulkimport_validate
/**
* The CSV file is parsed here so validation errors can be returned to the
* user. The data from a successful parsing is stored in the <var>$LEAP2AFILES</var>
* array so it can be accessed by the submit function
*
* @param Pieform $form The form to validate
* @param array $values The values submitted
*/
function bulkimport_validate(Pieform $form, $values)
{
global $LEAP2AFILES, $USER;
// Don't even start attempting to parse if there are previous errors
if ($form->has_errors()) {
return;
}
require_once 'csvfile.php';
$zipfile = $values['file'];
if (!is_file($zipfile)) {
$form->set_error('file', get_string('importfilenotafile', 'admin'));
return;
}
if (!is_readable($zipfile)) {
$form->set_error('file', get_string('importfilenotreadable', 'admin'));
return;
}
// Create temporary directory
$importdir = get_config('dataroot') . 'import/' . $USER->get('id') . '/' . time() . '/';
if (!check_dir_exists($importdir)) {
throw new SystemException("Couldn't create the temporary export directory {$importdir}");
}
$command = sprintf('%s %s %s', escapeshellcmd(get_config('pathtounzip')), escapeshellarg($zipfile), '-d ' . escapeshellarg($importdir));
$output = array();
exec($command, $output, $returnvar);
if ($returnvar != 0) {
log_debug("unzip command failed with return value {$returnvar}");
// Let's make it obvious if the cause is obvious :)
if ($returnvar == 127) {
log_debug("This means that 'unzip' isn't installed, or the config var \$cfg->pathtounzip is not" . " pointing at unzip (see Mahara's file lib/config-defaults.php)");
}
throw new SystemException(get_string('unzipfailed', 'admin', hsc($zipfile)));
} else {
log_debug("Unzipped {$zipfile} into {$importdir}");
}
$csvfilename = $importdir . '/usernames.csv';
if (!is_readable($csvfilename)) {
$form->set_error('file', get_string('importfilemissinglisting', 'admin'));
return;
}
$csvusers = new CsvFile($csvfilename);
$csvusers->set('headerExists', false);
$csvusers->set('format', array('username', 'filename'));
$csvdata = $csvusers->get_data();
if (!empty($csvdata->errors['file'])) {
$form->set_error('file', get_string('invalidlistingfile', 'admin'));
return;
}
foreach ($csvdata->data as $user) {
$username = $user[0];
$filename = $user[1];
$LEAP2AFILES[$username] = "{$importdir}/users/{$filename}";
}
}
示例7: importskinform_validate
function importskinform_validate(Pieform $form, $values)
{
global $USER, $SESSION;
$filetype = $values['file']['type'];
if (!$filetype || $filetype != 'text/xml') {
$form->set_error('file', get_string('notvalidxmlfile', 'skin'));
}
require_once 'file.php';
require_once 'uploadmanager.php';
$um = new upload_manager('file');
if ($error = $um->preprocess_file()) {
$form->set_error('file', $error);
}
}
示例8: bulkimport_validate
/**
* The CSV file is parsed here so validation errors can be returned to the
* user. The data from a successful parsing is stored in the <var>$LEAP2AFILES</var>
* array so it can be accessed by the submit function
*
* @param Pieform $form The form to validate
* @param array $values The values submitted
*/
function bulkimport_validate(Pieform $form, $values)
{
global $LEAP2AFILES, $USER;
// Don't even start attempting to parse if there are previous errors
if ($form->has_errors()) {
return;
}
require_once 'csvfile.php';
$zipfile = $values['file'];
if (!is_file($zipfile)) {
$form->set_error('file', get_string('importfilenotafile', 'admin'));
return;
}
if (!is_readable($zipfile)) {
$form->set_error('file', get_string('importfilenotreadable', 'admin'));
return;
}
// Create temporary directory
$importdir = get_config('dataroot') . 'import/' . $USER->get('id') . '/' . time() . '/';
if (!check_dir_exists($importdir)) {
throw new SystemException("Couldn't create the temporary export directory {$importdir}");
}
$archive = new ZipArchive();
if ($archive->open($zipfile) && $archive->extractTo($importdir)) {
// successfully extracted
$archive->close();
log_debug("Unzipped {$zipfile} into {$importdir}");
} else {
throw new SystemException(get_string('unzipfailed', 'admin', hsc($zipfile)));
}
$csvfilename = $importdir . '/usernames.csv';
if (!is_readable($csvfilename)) {
$form->set_error('file', get_string('importfilemissinglisting', 'admin'));
return;
}
$csvusers = new CsvFile($csvfilename);
$csvusers->set('headerExists', false);
$csvusers->set('format', array('username', 'filename'));
$csvdata = $csvusers->get_data();
if (!empty($csvdata->errors['file'])) {
$form->set_error('file', get_string('invalidlistingfile', 'admin'));
return;
}
foreach ($csvdata->data as $user) {
$username = $user[0];
$filename = $user[1];
$LEAP2AFILES[$username] = "{$importdir}/users/{$filename}";
}
}
示例9: accountprefs_validate
function accountprefs_validate(Pieform $form, $values)
{
global $USER;
$authobj = AuthFactory::create($USER->authinstance);
if (isset($values['oldpassword'])) {
if ($values['oldpassword'] !== '') {
global $USER, $authtype, $authclass;
try {
if (!$authobj->authenticate_user_account($USER, $values['oldpassword'])) {
$form->set_error('oldpassword', get_string('oldpasswordincorrect', 'account'));
return;
}
} catch (UserException $e) {
$form->set_error('oldpassword', $e->getMessage());
return;
}
password_validate($form, $values, $USER);
} else {
if ($values['password1'] !== '' || $values['password2'] !== '') {
$form->set_error('oldpassword', get_string('mustspecifyoldpassword'));
}
}
}
if ($authobj->authname == 'internal' && $values['username'] != $USER->get('username')) {
if (!AuthInternal::is_username_valid($values['username'])) {
$form->set_error('username', get_string('usernameinvalidform', 'auth.internal'));
}
if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', array(strtolower($values['username'])))) {
$form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
}
}
if (isset($values['urlid']) && get_config('cleanurls') && $values['urlid'] != $USER->get('urlid')) {
if (strlen($values['urlid']) < 3) {
$form->set_error('urlid', get_string('rule.minlength.minlength', 'pieforms', 3));
} else {
if (record_exists('usr', 'urlid', $values['urlid'])) {
$form->set_error('urlid', get_string('urlalreadytaken', 'account'));
}
}
}
if (get_config('allowmobileuploads')) {
foreach ($values['mobileuploadtoken'] as $k => $text) {
if (strlen($text) > 0 && !preg_match('/^[a-zA-Z0-9 !@#$%^&*()\\-_=+\\[{\\]};:\'",<\\.>\\/?]{6,}$/', $text)) {
$form->set_error('mobileuploadtoken', get_string('badmobileuploadtoken', 'account'));
}
}
}
plugin_account_prefs_validate($form, $values);
}
示例10: editsitepage_validate
function editsitepage_validate(Pieform $form, $values)
{
$allowedinstitutions = get_institution_selector(false);
if (array_search($values['pageinstitution'], array_flip($allowedinstitutions['options'])) === false) {
$form->set_error(null, get_string('staticpageinstitutionbad', 'admin', $values['pageinstitution']));
}
}
示例11: editgroup_validate
function editgroup_validate(Pieform $form, $values)
{
$cid = get_field('group', 'id', 'name', $values['name']);
if ($cid && $cid != $values['id']) {
$form->set_error('name', get_string('groupalreadyexists', 'group'));
}
}
示例12: contactus_validate
function contactus_validate(Pieform $form, $values)
{
$captcharequired = get_config('captcha_on_contact_form');
if ((is_null($captcharequired) || $captcharequired) && !$values['captcha']) {
$form->set_error('captcha', get_string('captchaincorrect'));
}
}
示例13: accountprefs_validate
function accountprefs_validate(Pieform $form, $values)
{
global $USER;
$authobj = AuthFactory::create($USER->authinstance);
if (isset($values['oldpassword'])) {
if ($values['oldpassword'] !== '') {
global $USER, $authtype, $authclass;
if (!$authobj->authenticate_user_account($USER, $values['oldpassword'])) {
$form->set_error('oldpassword', get_string('oldpasswordincorrect', 'account'));
return;
}
password_validate($form, $values, $USER);
} else {
if ($values['password1'] !== '' || $values['password2'] !== '') {
$form->set_error('oldpassword', get_string('mustspecifyoldpassword'));
}
}
}
if ($authobj->authname == 'internal' && $values['username'] != $USER->get('username')) {
if (!AuthInternal::is_username_valid($values['username'])) {
$form->set_error('username', get_string('usernameinvalidform', 'auth.internal'));
}
if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', strtolower($values['username']))) {
$form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
}
}
}
示例14: changerole_validate
function changerole_validate(Pieform $form, $values)
{
global $user, $group;
if (!group_can_change_role($group->id, $user->id, $values['role'])) {
$form->set_error('role', get_string('usercannotchangetothisrole', 'group'));
}
}
示例15: creategroup_validate
function creategroup_validate(Pieform $form, $values)
{
//global $USER;
//global $SESSION;
if (get_field('group', 'id', 'name', $values['name'])) {
$form->set_error('name', get_string('groupalreadyexists', 'group'));
}
}